A quick tutorial on AWK command | Latest | Engineer

Published: 30 April 2020
on channel: Engineerhoon
1,997
44

Watch the latest (2021) tutorial on AWK command:    • Video  


AWK command

Actions:

This command is mostly used for pattern scanning and processing. It allows us to use variables, logical operations, numeric and string functions, etc.

Syntax:

awk 'pattern { actions } ' inputfile

Some built-in variables :

NR - Keeps the current count of the number of records
NF - Keeps the current count of the number of fields within the current input field
FS - Field Separator
RS - Record separator
ORS - Output Record Separator (Default ORS is newline)
OFS - Output Field Separator (Default ORS is blank space)

Below are some commands using awk:


awk '{print}' testfile.txt

awk '/TCS/{print}' testfile.txt

awk '/TCS/{print $1}' testfile.txt

awk '/TCS/{print $0}' testfile.txt

awk '/TCS/{print NR,$0}' testfile.txt

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

awk '{if($4=="TCS")}{print NR,$0}' testfile.txt

awk '{if($4=="TCS")} END{print NR,$0}' testfile.txt

awk '{print $1,NF}' testfile.txt

awk '{print $1,$NF}' testfile.txt

awk '{print $1,$(NF-1)}' testfile.txt

awk 'NR==3, NR==4{print $1,$(NF-1)}' testfile.txt

awk 'NR==3, NR==6{print $1,$(NF-1)}' testfile.txt

awk '{print $1 ":"$(NF-1)}' testfile.txt

awk '{print $1,$(NF-1)}' testfile.txt

awk 'BEGIN{OFS=":";}{print $2,$NF}' testfile.txt

awk 'BEGIN{ORS=":";}{print $2,$NF}' testfile.txt

awk 'BEGIN{ORS="\n\n\n";}{print $2,$NF}' testfile.txt

awk '{print $2,$NF}' testfile.txt

======================
Important playlists
======================
Data Structures    • Introduction to Data Structures  
Linux:    • How to use VIM/VI editor for beginner...  
SonarQube:    • Install and configure SonarQube serve...  

======================
You can follow me on:
======================

Instagram:   / engineerhooon  
LinkedIn:   / sunny-shaw  
Github: https://github.com/sunny-shaw
Medium:   / sunnyshaw_12357  

=============================================================
|| Subscribe and hit the bell button to get latest content ||
=============================================================


Watch video A quick tutorial on AWK command | Latest | Engineer online without registration, duration hours minute second in high quality. This video was added by user Engineerhoon 30 April 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,997 once and liked it 44 people.