Removing punctuations from file input or standard input
Just started learning Unix and received my first assignment recently. We haven't learned many commands and honestly, I'm stumped. I'd like to receive assistance/guidance/hints.
1. The problem statement, all variables and given/known data:
How do I write a shell script that takes in a file or stdin that removes all the punctuation from it?
The shell script should be called from two ways:
removePunc FILENAME, where it reads a file in called FILENAME
removePunc, where it reads in standard input
For example, if the input is:
"Hello", she said. "Nice to meet you!", he {thought aloud}.
Then the output should be:
Hello she said Nice to meet you he thought aloud
The script must also accept one option, -r chars, where chars specifies characters to be removed from input. These characters are to be removed instead of the standard punctuation characters mentioned earlier.
2. Relevant commands, code, scripts, algorithms:
3. The attempts at a solution (include all code and scripts):
I really don't know where to begin, but I have a few concepts in mind. Can it be done by using sed or tr with a
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Adelaide University, Adelaide SA, Australia, David Knight, CS2005
Regards.
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Research regular expressions.
The following are some of the special groups that can be specified:
[:alnum:] - Alphanumeric characters.
[:alpha:] - Alphabetic characters
[:blank:] - Blank characters: space and tab.
[:digit:] - Digits: '0 1 2 3 4 5 6 7 8 9'.
[:lower:] - Lower-case letters: 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.
[:space:] - Space characters: tab, newline, vertical tab, form feed, carriage return, and space.
[:upper:] - Upper-case letters: 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.
Research regular expressions.
The following are some of the special groups that can be specified:
[:alnum:] - Alphanumeric characters.
[:alpha:] - Alphabetic characters
[:blank:] - Blank characters: space and tab.
[:digit:] - Digits: '0 1 2 3 4 5 6 7 8 9'.
[:lower:] - Lower-case letters: 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.
[:space:] - Space characters: tab, newline, vertical tab, form feed, carriage return, and space.
[:upper:] - Upper-case letters: 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.
Hmm, so [: punct:] would be a good place to start with?
Hmm, so [: punct:] would be a good place to start with?
In principle: yes, but as you want to implement the "-r" option you need to break down this class to its member characters anyway.
You might want to start with the following thought: how does a script receive input? There are two ways: via <stdin> and via a file it reads from. If you use:
The script is supposed to open that file and get its input by reading from it. If - in opposition to that - you use
or
The script gets its input by reading from <stdin>. You should start by researching and understanding how a script gathers input in these two ways prior to changing this input.
In principle: yes, but as you want to implement the "-r" option you need to break down this class to its member characters anyway.
You might want to start with the following thought: how does a script receive input? There are two ways: via <stdin> and via a file it reads from. If you use:
The script is supposed to open that file and get its input by reading from it. If - in opposition to that - you use
or
The script gets its input by reading from <stdin>. You should start by researching and understanding how a script gathers input in these two ways prior to changing this input.
I hope this helps.
bakunin
I see. I was thinking of using an if else statement to check whether if there is an argument for the command or not. If there is an argument, then the command would use that argument, which is the file input. If there is none, then it is through standard input.
I want to use a content of a file as standard input to a program and dump the output to a file. However, when I try the following code:
./program < input.in > output.out
The output.out is empty. So, how can I handle this problem?
Thanks in advance! (11 Replies)
Hi Geeks,
I am relatively new to Unix. Trying out to achive a shell script by hard learning. Here is my requirment.
1. I have to search for specified strings that are given in .csv file in the directory to find the files for matching strings in the .csv file.
2. If match is found, copy... (1 Reply)
So, I am new to shell scripting and have a few problems.
I know how to read from standard input but I do not know how to really compare it to say, a character. I am trying to compare it to a character and anything exceeding just a character, the user will get an output message, but the program... (7 Replies)
Hello,
I am new to scripting.
How do I read multiple lines from the command line?
I know read reads one line, but if I have to read multiple lines, how should I do?
Thanks,
Prasanna (4 Replies)
Hi
I am trying to write a shell script which should take the file as standard input. As file(content and name both) will change for each run. It should read the file line by line. with each line I have to perform certain operation.
For example
I have i file foo, it looks like
/usr/doc/abc... (4 Replies)
Hi,
How can I removed the directory in the input file?
The script responsible for storing the report in an input file is this:
while }" ]
do
echo "penetration|${penfilename}|${penfilenamedaterange}" >> ${OUT_DIR}/penrpt_emailfile.txt
(( i=i+1 ))
done
For the penfilename:
... (2 Replies)
I tried copy the output files from find command into a directory.
Example,
find / -name core 2>/dev/null | xargs cp????
I have known that we can use xargs to execute command lines from standard input but how to use it in this case.
Or I can do something besides xargs. (2 Replies)
how can i redirect standard input? i dont remember :/, though could you redirec not from a command? i mean, to redirect always stdin and stout (1 Reply)
In perl I want to do remove the top line of my input file then process the next line. I want to do something like
head -1 inputfile > temp
grep -v temp inputfile > newinputfile
cp newinputfile inputfle
is this possible in perl? (3 Replies)