AWK COMMAND IN LINUX

1. awk ‘{print $1}’ input_file

2. awk ‘{ if($9 == “t4”) print $0;}’ input_file

3. awk ‘{ if($9 == “t4”) print $0;}’ input_file

4. awk -F: ‘{print $2} input_file

5.  awk ‘{print $4,$5}’ input_file

NF – Number of fileds variable:

The NF can be used to know the number of fields in line

6. awk ‘{print NF}’ input_file
This will display the number of columns in each row.

NR – number of records variable:
The NR can be used to know the line number or count of lines in a file.

7. awk ‘{print NR}’ input_file
This will display the line numbers from 1.

8. awk ‘END {print NR}’ input_file
This will display the total number of lines in the file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s