grep, sed, and awk

grep and egrep

grep 'Michael Jang' /etc/passwd looks for  michael jang in the /etc/passwd file.



wc

wc -w filename returns the number of words in that file.
wc -l  /etc/passwd  returns the number of line in passwd file
wc -c /etc/passwd returns the number of character in the passwd file

sed

#swap first windows to linux in every line and save to new file
 sed 's/Windows/Linux/' opsys > newopsys
# swap every windows to linux in every line and save to new file
sed 's/Windows/Linux/g' opsys > newopsys

awk

#read out the username of every user with a Mike
 in column 1 of /etc/passwd
 awk '/Mike/ {print $1}' /etc/passwd

# apply all users with user1's quota
edquota -p user1 `awk -F: '$3 > 499 {print $1}' /etc/passwd`
Then if you want to enable grace periods for all users, run the edquota -t command.

# print user id and user name in /.etc/passwd  with space
awk -F: ' {print $3,$1} ' /etc/passwd

# print field 1 2 3 without space
awk -F : '{ print $1 $2 $3 ]' /etc/passwd





 
 

你可能感兴趣的:(职场,休闲)