Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

20 useful AWK single-line statements

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

20 useful AWK single-line statements

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report