Introduction to the use of LINUX awk commands

AWK is a language for processing text files and is a powerful text analysis tool. Here are only a few of the most commonly used usages.

awk commands are performed line by line.

1. awk '{print $1}' 123.txt #Read the contents of 123.txt by line and separate them with default spaces, and take the first paragraph.


2. awk -F ":" '{print $1}' 123.txt #Read the contents of 123.txt line by line and separate them with: to take the first paragraph.


3. awk 'BEGIN{FS=":"} {print $1}' 123.txt #Complete writing of the previous one


4. awk -F "[,:]+" '{print $1}' 123.txt #Read and use the content in 123.txt by line, and: Separate, take the first paragraph


5. awk 'NR==5' 123.txt #Read line 5 in 123.txt


6. awk 'NR>2 && NR<9' 123.txt #Read lines 3 to 8 in 123.txt


7. awk -F ":" '{print $3":"$2":"$1}' 123.txt #Separate each line in 123.txt by: and output in reverse order

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325935341&siteId=291194637