Unix Commands With Examples and AWK
Unix Commands With Examples and AWK
fruits.txt
------------------------
fruit_id,fruit_name,fruit_qty,unit_price,total_price
1,Mango,2,10,20
2,Apple,6,15,90
3,Banana,4,8,32
4,Watermelon,7,9,63
5,apple,3,15,45
cat
Example:
cat fruits.txt
grep
Example:
sort
Example:
Unix and AWK Guide (With Examples)
uniq
Example:
cut
Example:
awk
Example:
sed
Example:
head
Example:
head -n 2 fruits.txt
tail
Example:
tail -n 2 fruits.txt
wc
Example:
wc -l fruits.txt
find
Example:
ls
Unix and AWK Guide (With Examples)
Example:
ls -l
chmod
Example:
Command:
Explanation:
Skips header (NR > 1) and prints the 2nd field (Name).
Command:
Explanation:
Command:
awk -F@ 'NR > 1 && $4=="Sales" { print $2 }' employees.txt | sort -r
Explanation:
Selects only Sales department employees and sorts names in reverse order.
Command:
awk -F@ 'NR > 1 && $5 > 60000 { print $2 "@" $5 }' employees.txt
Explanation:
Command:
awk -F@ 'NR > 1 && $4=="HR" { count++ } END { print count }' employees.txt
Explanation:
Command:
awk -F@ 'NR > 1 { sum += $5 } END { print sum }' employees.txt
Explanation:
Command:
awk -F@ 'NR > 1 && $3 > 40 { print $2, $3 }' employees.txt
Unix and AWK Guide (With Examples)
Explanation:
Command:
awk -F@ 'NR > 1 && $4=="Marketing" { sum+=$5; count++ } END { print sum/count }' employees.txt
Explanation:
Command:
awk -F@ 'NR == 2 || $5 < min { min=$5; name=$2 } END { print name, min }' employees.txt
Explanation:
Command:
awk -F@ 'NR > 1 { inc = $5 * 1.10; print $2, inc }' employees.txt
Explanation:
Command:
Explanation:
Unix and AWK Guide (With Examples)
Command:
Explanation:
Command:
Explanation:
The '^' symbol matches beginning of string; selects names starting with 'S'.
Command:
Explanation:
The '$' symbol matches end of string; selects names ending with 'a'.
Command:
Explanation:
Command:
Explanation: