Professional Documents
Culture Documents
To delete line:
cat -n file | sed ‘3d’
cat -n file | sed ‘3,5d’
cat -n file | sed -r ‘/FRANK/d’ (Delete line where the pattern matches)
cat -n file | sed ‘/^$/d’ (Delete all the blank line)
cat -n file | sed -e ‘/ *$//’ (Delete all the spaces at the end of the line)
cat -n file | sed -e ‘s/ #.*//g’ (Delete # and anything after that, all the comments)
Variables:
$0 -entire line
$1,$2,$3….$n -1st column, 2nd column, 3rd column…..nth column
NR -line number in the given input file
NF -number of columns in each line of the given input file
100|Thomas|Manager|Sales|5000|21/01/98
200|Jason|Developer|Technology|5500|22/02/89
300|Sanjay|Sysadmin|Technology|7000|23/03/78
400|Nisha|Manager|Marketing|9500|24/04/87
500|Randy|DBA|Technology|6000|25/05/67
600|Chowdhary|DBA|Marketing|7000|26/06/76
700|Choudhary|Manager|Technology|8000|27/07/93
Number comparison:
awk -F"|" '$5 > 600 && $4 ~ "Technology" {print $0,$5*.25,$5*.50}' emp_ns.txt
Calculate bonus for all the employees and add it along with input file:
awk -F"|" 'BEGIN { bonus_pct=.25; } { bonus=$5*bonus_pct;print $0"|"bonus }' emp_ns.txt