In: Computer Science
I am a student taking an introductory Unix / LInux shell programming course and need some help with an assignment.
Using the file CISED as input, write the sed command to do the following:
Change 2 or more occurrences of g to a single g
Add > to beginning of any line that begins with CIS132
Add < to the end of any line that ends in Tux or tux
Replace any five to eight digit number with XX
For every line that begins with CIS132, place the first 6 characters in the line at the end of the line and the last three characters at the beginning of the line. Leave the characters in between these characters as they were.
Change any non alphanumeric character to &
For any line that begins with CIS132 place the entire line inside of double quotes.
Thanks for your help.
Please find the following sed commands to edit the file.
Change 2 or more occurrences of g to a single g
sed 's/g\{2,\}/g/g' <inputfile
Add > to beginning of any line that begins with CIS132
sed 's/^CIS132/\<CIS132/g' <inputfile
Add < to the end of any line that ends in Tux or tux
sed 's/Tux$/Tux\>/g' <inputfile
sed 's/tux$/tux\>/g' <inputfile
Replace any five to eight digit number with XX
sed 's/[0-9]\{5,8\}/XX/g' <inputfile
For every line that begins with CIS132, place the first 6 characters in the line at the end of the line and the last three characters at the beginning of the line. Leave the characters in between these characters as they were.
sed 's/^\(CIS132\)\(.*\)\(...\)$/\3\2\1/' <inputfile
Change any non alphanumeric character to &
sed 's/[^a-zA-Z0-9]/\&/g' <sedFile
For any line that begins with CIS132 place the entire line inside of double quotes.
sed 's/^\(CIS132.*\)/"\1"/' <inputfile
Screen Shot: