#!/bin/bash dir=/home/hopper/berezin/Data psef=/home/hopper/berezin/Data/psef passwd=/home/hopper/berezin/Data/passwd etcList=/home/hopper/berezin/Data/etcList etcSlist=/home/hopper/berezin/Data/etcSlist # problem 01 - change the first occurrence of a to b sed 's/a/b/' $passwd > sout.01 # problem 02 - change 2nd occurrence of x to y sed 's/x/y/2' $passwd > sout.02 ... etc
where sout has the problem number appended to it for each problem.
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 the results of your 1st 7 solutons by using my data set and using diff to compare the souts files generated by solutions which can be found in '/home/hopper/Sed'.
Create a function, similar to the one outlined in the grep assignment, that invokes diff and compares my answers to yours.
function sdiffit () { 'diff sout.$1 /home/hopper/berezin/Sed/sout.$1 }
Unless stated otherwise, when a string is generically described as a word, treat a word as alpha, numeric, and underscore. If specific word given, treat as literal unless otherwise specified. If it says find the word dog, look for lower case "dog" unless the problem indicates otherwise.
Keep in mind, the passwd file uses a : as a field delimiter.
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. You may use multiple -e options. But unless specified, do not use any other sed options.
Once that line has been identified, append :daemon to the end of the line.
So :
sshd:x:114:65534::/var/run/sshd:/usr/sbin/nologin
Will look like :
sshd:x:114:65534::/var/run/sshd:/usr/sbin/nologin:daemon
Remember : separate fields in the passord file, so using square brackets and the not, [^:], is useful.
So :
z1763923 10584 10583 0 09:39 pts/24 00:00:00 -bash
Will look like :
z1763923 10584 10583 0 09:39 pts/24 00:00:00 -bash : z1763923
Check out \(\) and &. Parentheses are numbered from the left and they may be embedded. \(\(...\)....\) is legal.