Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the common AWK one-line statements?

Shulou Source: shulou.com Published: 2022-06-03 05:36:06 10月04日 Update

Today, the editor will bring you an article about common AWK one-line statements. The editor thinks it is very practical, so I will share it for you as a reference. Let's follow the editor and have a look.

1. END {print NR} # output total number of lines

2. NR = = 10 # output line 10

3. {print $NF} # output the last column

4. {field = $NF} END {print field} # output the last column of the last line

5. NF > 4 # output all rows with more than 4 columns in input line (this is not in action, so it is a filtering function)

6. $NF > 4 # output all rows with values greater than 4 in the last column of the input line, which is also a filter

7. All cumulative total fields of {nf = nf + NF} END {print nf} # input line

8. / Beth/ {nlines = nlines + 1} END {print nlines} # the total number of lines containing the word Beth

9. $1 > max {max = $1; maxline = $0} END {print max, maxline} # output the largest row in the first column

10. NF > 0 # field outputs non-empty lines

11. Length ($0) > 80 # filter out rows with a length of more than 80

12. {print NF, $0} # output how many columns there are in front of the line

13. {print $2, $1} # output the second column, space, and first column of each row

14. {temp = $1; $1 = $2; $2 = temp; print} # output all rows after the first and second columns swap positions

15. {$1 = NR; print} # replace the first column with the line number and output the line

16. {$2 = "; print} # clear the second column and output all rows

17. {for (I = NF; I > 0; I = I-1) printf ("% s", $I); printf ("\ n")}

# output the whole line in reverse order

18, {sum = 0; for (I = 1; I

Tags: Output common statement one line sum total line more find out in line practical maximum for this location content function word article line positive number look Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Xiaomi Huawei Microsoft