Tuesday, April 5, 2022

Linux - AWK command

 Awk is a scripting language used for manipulating data and generating reports

Default behavior:- It prints each line of data from the specified file.

awk '{print}' simple.txt

Print the matching Pattern

awk '/manager/ {print}' emplyee.txt

Print fields data

awk '{print $1}' emplyee.txt

awk '{print $1,$2}' emplyee.txt

awk '{print $4,$2}' emplyee.txt

Display the file content with Line number

awk '{print NR,$0}' emplyee.txt

Display the file content from lines number 3 to 6

awk 'NR==3, NR==6 {print NR,$0}' emplyee.txt

Display the file content with concatenation with other fields

awk 'NR==3, NR==6 {print NR "-" $1}' emplyee.txt

Use NF Variable  to display the last Field

awk '{print $NF}' emplyee.txt

To Print the empty line of a file

awk 'NF == 0 {print NR}' emplyee.txt

Find the length of Longest line

 awk '{ if (length($0) >max) max =length($0) } END { print max }' emplyee.txt

Total number of lines

awk 'END { print NR }' emplyee.txt




0 comments:

Post a Comment