Question: Implement a program sub that makes a copy of the content of a file substituting one character for another The program should print the following
Implement a program sub that makes a copy of the content of a file substituting one character for another
The program should print the following help message that explains the functionality of the utility:
USAGE: sub [ -h | --fromChars -+toChars [-i inputFile] [-o outputFile DESCRIPTION: This utility copies text from an input stream to an output stream replacing every instance of a specific character in fromChars with a corresponding (position-wise) character from toChars. Any characters in fromChars and in toChars that do not have corresponding counterparts in the other one are ignored. If an input file is provided, the content is read from that file; otherwise, the standard input is used. If an output file is provided, then the modified content is written to that file; otherwise, the standard output is used. OPTIONS: -- (followed by a string without separating space) indicates all characters that will be replaced in the processed text + (followed by a string without separating space) indicates the characters that will be used to replace corresponding (position-wise) characters from fromChars in the processed text -i (followed by input file name) use the provided file as an input stream instead of standard input -o (followed by output file name) use the provided file as an output stream instead of standard output -h prints this help message; it is also a default if no command line arguments are provided Examples $ sub sub -h Both invocation should display the help information for the utility as specified earlier. $ sub --a -+x -i src.txt -o dest.txt $ sub -i src.txt -o dest.txt --a -+x $ sub -o dest.txt --a-i src.txt -+x $ sub--a -o dest.txt -+x -i src.txt All commands with any order of the arguments copy the content of src.txt to dest.txt with all instances of "a" in src.txt replaced by "x" in dest.txt. $ sub --a -+x -i src.txt This will copy the content of src.txt to the standard output with all instances of "a" replaced with "x", $sub-a -+x -o dest.txt This will copy user input from standard input to dest.txt with all instances of "a" replaced with "x".
Step by Step Solution
3.45 Rating (155 Votes )
There are 3 Steps involved in it
python code is as follows import argparse import sys def substitutecharactersinputstream outputstrea... View full answer
Get step-by-step solutions from verified subject matter experts
