The simplest use of awk

awk '{[pattern] action}' {filenames}   

When using with other commands, plus the | do pipeline
For example, if you want to view the IP address of the network card:

piky@LAPTOP-I41H962O:/mnt/d/code/shelltest$ ifconfig eth0 | awk '/inet/ {print $2}'
169.254.174.29
fe80::1de4:b97f:e1c5:ae1d

As used herein, | speak ifconfig eth0 output point to awk, awk match inet, if hit, the output of the second field

A display content of the first level directory under /

ls $(ls / -all | awk '/root/ {print "/"$9}')

As used herein, the transmission output $ () to the ls, (), the output of multiple rows, each row as a parameter to the result ls

awk default string space as delimiter, if desired custom, with the use of -F

Guess you like

Origin www.cnblogs.com/luckpiky/p/11518059.html