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

The use of awk and the output of printf format

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1 basic usage awk-F:'{print$1}'/ etc/passwd # shows the user name of passwd awk-F:'$NF== "/ bin/bash" {print$1, $NF}'/ etc/passwd # shows the user awk 'BEGIN {print "beginning"} {print$0} END {print "}' / etc/passwd # BENGIN with shell as" / bin/bash "can be understood as a page header END is understood as footer df-h | awk-F%'/ ^\ / dev/ {print $1}'| awk'{if ($5 > = 20) print $1 # 5 "%"} # matches dev first, and the one that begins with dev is really mounted to find those with disk space greater than 20%. The idea is to first cut the first section of the pipe into two segments with%. This is the desired value of $5. If the comparison is greater than 20, output awk'{FS= ":" OFS= "- -"} {print NR,$1,$2,$3}'/ etc/passwd # is delimited by: awk-F for the use of the output delimiter 2.AWK if ":"'{if ($1mm = "root") print$0}'/ etc/passwd # used by a single if, the first field is displayed when the content is equal to "root". Awk-F ":'($1percent =" root ") {print$0}'/ etc/passwd # another way of writing, as above, without the need for if to use (), awk-F": "'{if ($1mm =" root ") next} {print$0}'/ etc/passwd # for single if use, the first field equals" root "is skipped, the display behind, and the opposite of the above shows # next directly skipped this time, exit exits directly But if you have EOF, you still need to execute the content of EOF awk-F:'{if (NR > = 2&&NR).

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