#!/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 sol=/home/hopper/berezin/Sed #1 change user ID, 1st word of line, form root to Master. sed "s/^root\>/Master/" $psef > $sol/sout.01 #sed "s/^root /Master/" $psef > $sol/sout.01 #2 Change /home/hopper to /system/tron. Don't use backslashes sed "s#/home/hopper#/system/tron#" $passwd > $sol/sout.02 #3 Add the flag : daemon to end of any line belonging to a daemon # recognized by id endding with a d sed "/^[^:]*d\>/ s/$/:daemon/" $passwd > $sol/sout.03 #4 copy user Id to end of line if it is a z-id, starts with z sed "s/^\(z[^:]*\)\>.*$/& : \1/" $psef > $sol/sout.04 #5 Change 2nd occurrence of root to wheel sed "s/root/wheel/2" $etcList > $sol/sout.05 # better, if you really are targeting the word root sed "s/\/wheel/2" $etcList > $sol/sout.05 #6 Replace 24 contiguous spaces with 4 spaces. # this should affect only the 1st 24 contiguous spaces. sed "s/ \{24\}/ /" $etcSlist > $sol/sout.06 #7 Print only lines where user id is 4-6 characters long. sed -n "/^[^:]\{4,6\}:/p" $passwd > $sol/sout.07 #8 Write a function that tests a string for lack of spaces. function NoSpace () { # grep may hve -s and -q, but these are not universal # so redirection of output and error is more consistant echo "$*" | grep -v " " >/dev/null 2>&1 # The following may be redundent. # testing this, I've found that if return not used, the function # exits with the return code of the last executed command. return $? } #9 Write a function that tests a string for only digits. function IsDigits () { echo "$*" | grep "^[0-9][0-9]*$ " >/dev/null 2>&1 return $? } #10 Write a function that checks for a floating point number. function IsFloat () { echo "$*" | grep -e "^[0-9][0-9]*\.[0-9]*$" -e "^[0-9]*\.[0-9][0-9]*$" 2> /dev/null return $? }