There are 11 problems in this part of the assignment.
Create a text file that contains a set of sed commands that perform the
following actions. The files to be edited will be found in
/home/max/berezin/Data. Your command file look something like:
# problem 02
sed 's/x/y/' $ipasswd > sout.02
... etc
Each problem should include one or more comment lines explaining what you are doing.
You can change the contents of the data variable if you wish to run the sed commands on your own data set. But set it back before handing in the assignment. You can test your answer using my data set by using diff to compare the sout files generated with my copies to be found in /home/max/berezin/Data/Ans. Create an alias sdiffit that is defined as follows.
Each password entry uses a : as a field delimiter.
If you spot differences between your solutions and mine, please inform me and I'll check the datasets, my solution, and the interpretation of the problem.
Write a complete sed statement that edits the specified file. Different problems use different data files. Use the appropriate variable to reference the appropriate file.
sout.1 substitute the first occurrence of the word csh on a line with sh Use the passwd file.
sout.2 substitute the second occurrence of the string *NP* on a line with the string null field Use the passwd file.
sout.3 substitute all occurrences of the character : on a line with ; Use the passwd file.
sout.4 swap the last two fields on a line. Fields are separated by : Use the passwd file.
sout.5 remove *NP* from the second field. Colons must stay. Use the passwd file.
sout.6 remove the contents (what ever the value) of the second field. Colons must stay. Use the passwd file.
sout.7 If the line starts with a t9 then substitute usr2 with usr3. Use the passwd file.
sout.8 replace all occurances /home/mp with /usr/ux. Use the passwd file.
sout.9 remove any periods. Use the password file.
sout.10 indent (one tab) all lines that do not begin with t9 Use passwd file.
sout.11 The syntax of the 5th field (4th field from end) in the passwd file is last_name first_name [middle name or initial]. Some entries have three words, some two, and some have multiple words and use comas. Use a single edit statement and remove the right most name or word from that field. Describe the string of interest from the end of the line. Use the : delimiter to parse fields and a space or coma to recognize the right most word of field. Use the passwd file.
sout.12 I have embedded a series of record markers, such as FACULTY, STUDENTS, SUPPORT, etc. They are the only word on the line. Indent by 2 spaces all lines found in a block delimited by FACULTY and some marker that is not FACULTY. Keep in mind the block markers are lines with only one word on them.
When you use a block address, keep in mind that the sub-block commands won't apply to the line that turns on block but will apply to the line that turns it off.