working with cut, translate, sed, awk

# cut -f 1 filename – filter a file.
Cut is using a separator for fields.
# cut -f 1 -d : /etc/passwd

# tr – translate is replace characters. It works with pipe | in order to work with the output from other command.
# echo hello | tr a-z A-Z
This command is show all uppercase.
This is working ok if there are not different letters.
# echo hello | tr [:lower:] [:upper:]
# man tr
and awk was for file processing. Now there are not used anymore.
# sed 2q /etc/passwd
show the first 2 lines from file
# sed -n /^root/p /etc/passwd
Sed is not using anymore because there are other commands which are nice: grep.
# cp /etc/passwd ~
Replace an user with something else:
# sed -i ‘s/linda/julia/g’ passwd
awk is doing many things which can be done with other tools. Cutting information:
# ps aux | grep apache
# ps aux | grep apache | cut -f 2
or
# ps aux | grep apache | awk ‘{ print $2 }’

1. Use head and tail to display the 5th line of file /etc/passwd
# head -n 5 /etc/passwd | tail -n 1
2. use sed to do the same.
# sed -n ‘5p’ /etc/passwd
3. use awk to filter the first column out of the results of command ps aux
# ps aux | awk ‘{ print $1 }’
4. use grep to show the names of all files in /etc that have lines starting with the text ‘root’
# cd /etc
# grep ^root * 2> /dev/null