Awk Command ( Practical use ) | Most Important Filter Command | Linux Tutorials | Parsutech 🔥🔥🔥🔥🔥🔥

Pubblicato il: 17 ottobre 2023
sul canale di: Parsu Tech
30
like

Hello Friends ,
Please subscribe my youtube channel and also like my videos.
If you have any type of doubt then please put in the comment section .
Subscribe please!!!!

Stay Tuned!!!!!

Awk Command :-

The awk command is a versatile and powerful text-processing tool commonly used in Unix and Linux environments. It is especially handy for working with structured data like CSV files, log files, and text reports. awk allows you to manipulate, filter, and format text or data, making it a valuable tool for data extraction and transformation.

The basic syntax of the awk command is as follows:
Syntax :- awk 'pattern { action }' input-file

Here's how awk works:
pattern specifies a condition that, when met, triggers the associated action.

action is a set of commands that will be executed when the pattern is true.

input-file is the file you want to process with awk.

Examples:-

ls l | awk ‘{print $1}’: it will give the first field as output.

ls l |awk ‘{print $1,$2,$7}’: it will give field one ,two and seven as output.

ls -l |awk ‘{print }’ or ls -l |awk ‘{print $0}’ :-it will give all the field as output.

ls l |awk ‘/^d/ {print $0}’: it will filter the all lines starting from ‘d’ or d means directory. ^(caret) symbol used to denote starting.

ls -l |awk ‘/^-/ {print $0}’:-it will filter all lines that starting from – (dash).

ls -l |awk ‘$2 ~ /^d/ {print $0}’:-it will search in the second field as $2 denotes that we have to search the query in field 2.

ls -l |awk ‘$2 ~/^1$/ {print $0}’:-it will retrieve the result present in field 2 and starting and ending with 1.^ mean starting and $ means end.

ls -l | awk ‘$5 = 1024 {print $0}’:-it will give the data which has size greater than or less than or equal to 1024 .

ls l |awk ‘$5 =6 &&/|| $2=2 {print $0}’: it means the data which is of 6 bytes and/or also have 2 link that will be the output.

ls -l |awk ‘{print NR,$0}’:-it will give the result with number of the line NR means number record.

ls l |awk ‘{print NR,$0,NF}’: it will give the result with number of the line and also give the number of fields at the end of the each line.

ls l /* |awk ‘NR==920, NR==930 {print NR,$0,NF}’: it will give output from line 920 to 930.

ls -l /* |awk ‘$1 ~ /rwx------/ {print NR,$0,NF}’:-it will give the output of the given permission.

ls l /* |awk ‘BEGIN {count=0;} {if ($6==”Nov”) count+=1} END {print count}: it will give the output that how many times Nov is occurred in the sixth field.

awk F’:’’print $1,$3,$5’ /etc/passwd: F option is used to set delimiters. Here we have set the : colon as delimiter and awk command will break all the field by colon.


In questa pagina del sito puoi guardare il video online Awk Command ( Practical use ) | Most Important Filter Command | Linux Tutorials | Parsutech 🔥🔥🔥🔥🔥🔥 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Parsu Tech 17 ottobre 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 30 volte e gli è piaciuto like spettatori. Buona visione!