Lab 9-10 Linux Assignment and Solution

Lab 9-10 Linux Assignment Requirement

lab9-10

Lab 9-10 Shell Script Solution

** Module 9 **
1. script lab9-10
2. finger | head -3 > out1
3. finger | head -5 > out2

4. cmp out1 out2 -- EOF on out1

5. ls -a | wc -l
6.

-- 1. cat /etc/passwd | tail -6 -- last 6 line of the file

-- 2. cut -f1,7 -d':' /etc/passwd | tail -6 -- output on screen

3. cut -f1,7 -d':' /etc/passwd | tail -6 | tee out -- output on screen and file

7. head -2 out | tail -1
8. export LC_ALL="POSIX"
   who | cut -f1 -d' ' | sort -r | uniq
9. grep 'testUser' /etc/passwd | cut -f5 -d':' | tr [a-z] [A-Z] | tr -d ' '
10. cat /etc/passwd | cut -f4 -d':' | sort | uniq
11. cat /etc/passwd | cut -f1 -d':' | sort | tail -1
12. who | tr -s ' ' '$' | cut -f1,3,4,5 -d'$' | tr '$' ' ' | sort -Mnk +2 -k+3 -k+4
13. exit
** Module 10 **
1. script -a lab9-10
2. cp /home/distribution/cnguyen/cis18a/lab9-10input .
3. egrep [oO] lab9-10input
4. egrep [a-zA-Z]{5} lab9-10input

5. egrep [.]$ lab9-10input OR egrep ' \.'$ lab9-10input

6. egrep ^\ + lab9-10input
7. egrep '^[0-9/]+$|^[0-9\ ]+$' lab9-10input
8. egrep ^[^0-9a-zA-Z]+$ lab9-10input

-- Incorrect egrep ^\ *[^0-9a-zA-Z]+\ *$ lab9-10input

-- But how to avoid line having only blank space

9. egrep '^ *[a-zA-Z]{5} *$' lab9-10input
10. egrep '^[^t]+t{1}[^t]+$' lab9-10input
** Extra Credit **
11. egrep '^.*[0-9]*[.][0-9]{1,2}.*$|^.*[0-9]+[.][0-9]{2}[^0-9].*$' lab9-10input
12.
exit
clean.sh lab9-10
- Clean typing error
- Check difference between lab9-10.cleaned and lab9-10
- Turn in lab