{"id":3182,"date":"2019-06-13T14:50:26","date_gmt":"2019-06-13T06:50:26","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=3182"},"modified":"2022-05-09T15:54:23","modified_gmt":"2022-05-09T07:54:23","slug":"awk","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/awk","title":{"rendered":"awk\u547d\u4ee4 – \u6587\u672c\u548c\u6570\u636e\u8fdb\u884c\u5904\u7406\u7684\u7f16\u7a0b\u8bed\u8a00"},"content":{"rendered":"\n
awk\u547d\u4ee4\u6765\u81ea\u4e8e\u4e09\u4f4d\u521b\u59cb\u4eba\u201dAlfred Aho\uff0cPeter Weinberger, Brian Kernighan \u201c\u7684\u59d3\u6c0f\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8e\u5bf9\u6587\u672c\u548c\u6570\u636e\u8fdb\u884c\u5904\u7406\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u4f7f\u7528awk\u547d\u4ee4\u53ef\u4ee5\u8ba9\u7528\u6237\u81ea\u5b9a\u4e49\u51fd\u6570\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u6587\u672c\u5185\u5bb9\u8fdb\u884c\u9ad8\u6548\u7ba1\u7406\uff0c\u4e0esed\u3001grep\u5e76\u79f0\u4e3aLinux\u7cfb\u7edf\u4e2d\u7684\u6587\u672c\u4e09\u5251\u5ba2\u3002<\/p>\n\n\n\n
\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>awk \u53c2\u6570 \u6587\u4ef6<\/p>\n\n\n\n \u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n \u5185\u7f6e\u53d8\u91cf\uff1a<\/p>\n\n\n\n \u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n \u4ec5\u663e\u793a\u6307\u5b9a\u6587\u4ef6\u4e2d\u7b2c1\u30012\u5217\u7684\u5185\u5bb9\uff08\u9ed8\u8ba4\u4ee5\u7a7a\u683c\u4e3a\u95f4\u9694\u7b26\uff09\uff1a<\/p>\n\n\n\n \u4ee5\u5192\u53f7\u4e3a\u95f4\u9694\u7b26\uff0c\u4ec5\u663e\u793a\u6307\u5b9a\u6587\u4ef6\u4e2d\u7b2c1\u5217\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n \u4ee5\u5192\u53f7\u4e3a\u95f4\u9694\u7b26\uff0c\u663e\u793a\u7cfb\u7edf\u4e2d\u6240\u6709UID\u53f7\u7801\u5927\u4e8e500\u7684\u7528\u6237\u4fe1\u606f\uff08\u7b2c3\u5217\uff09\uff1a<\/p>\n\n\n\n \u4ec5\u663e\u793a\u6307\u5b9a\u6587\u4ef6\u4e2d\u542b\u6709\u6307\u5b9a\u5173\u952e\u8bcdroot\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n \u4ee5\u5192\u53f7\u4e3a\u95f4\u9694\u7b26\uff0c\u4ec5\u663e\u793a\u6307\u5b9a\u6587\u4ef6\u4e2d\u6700\u540e\u4e00\u4e2a\u5b57\u6bb5\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n awk\u547d\u4ee4\u6765\u81ea\u4e8e\u4e09\u4f4d\u521b\u59cb\u4eba\u201dAlfred Aho\uff0cPeter Weinberger, Brian Kernig […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3182"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=3182"}],"version-history":[{"count":12,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3182\/revisions"}],"predecessor-version":[{"id":9374,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3182\/revisions\/9374"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=3182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=3182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=3182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}-F<\/td> \u6307\u5b9a\u8f93\u5165\u65f6\u7528\u5230\u7684\u5b57\u6bb5\u5206\u9694\u7b26 <\/td><\/tr> -v<\/td> \u81ea\u5b9a\u4e49\u53d8\u91cf<\/td><\/tr> -f<\/td> \u4ece\u811a\u672c\u4e2d\u8bfb\u53d6awk\u547d\u4ee4<\/td><\/tr> -m<\/td> \u5bf9val\u503c\u8bbe\u7f6e\u5185\u5728\u9650\u5236 <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n \u53d8\u91cf\u540d\u79f0<\/td> \u8bf4\u660e<\/td><\/tr> ARGC<\/td> \u547d\u4ee4\u884c\u53c2\u6570\u4e2a\u6570<\/td><\/tr> ARGV<\/td> \u547d\u4ee4\u884c\u53c2\u6570\u6392\u5217<\/td><\/tr> ENVIRON<\/td> \u652f\u6301\u961f\u5217\u4e2d\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u7684\u4f7f\u7528<\/td><\/tr> FILENAME<\/td> awk\u6d4f\u89c8\u7684\u6587\u4ef6\u540d<\/td><\/tr> FNR<\/td> \u6d4f\u89c8\u6587\u4ef6\u7684\u8bb0\u5f55\u6570<\/td><\/tr> FS<\/td> \u8bbe\u7f6e\u8f93\u5165\u57df\u5206\u9694\u7b26\uff0c\u7b49\u4ef7\u4e8e\u547d\u4ee4\u884c -F\u9009\u9879<\/td><\/tr> NF<\/td> \u6d4f\u89c8\u8bb0\u5f55\u7684\u57df\u7684\u4e2a\u6570<\/td><\/tr> NR<\/td> \u5df2\u8bfb\u7684\u8bb0\u5f55\u6570<\/td><\/tr> OFS<\/td> \u8f93\u51fa\u57df\u5206\u9694\u7b26<\/td><\/tr> ORS<\/td> \u8f93\u51fa\u8bb0\u5f55\u5206\u9694\u7b26<\/td><\/tr> RS<\/td> \u63a7\u5236\u8bb0\u5f55\u5206\u9694\u7b26<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n [root@linuxcool ~]# awk ' {print $1,$2} ' anaconda-ks.cfg<\/strong>\n#version=RHEL8 \nignoredisk --only-use=sda\nautopart --type=lvm\n# Partition\nclearpart --none\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n
[root@linuxcool ~]# awk -F : '{print $1}' \/etc\/passwd<\/strong>\nroot\nbin\ndaemon\nadm\nlp\nsync\nshutdown\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n
[root@linuxcool ~]# awk -F : '$3>=500' \/etc\/passwd<\/strong>\nnobody:x:65534:65534:Kernel Overflow User:\/:\/sbin\/nologin\nsystemd-coredump:x:999:997:systemd Core Dumper:\/:\/sbin\/nologin\npolkitd:x:998:996:User for polkitd:\/:\/sbin\/nologin\ngeoclue:x:997:995:User for geoclue:\/var\/lib\/geoclue:\/sbin\/nologin\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n
[root@linuxcool ~]# awk '\/root\/{print}' anaconda-ks.cfg <\/strong>\nrootpw --iscrypted $6$n9sZuTcY8Yzk4l.Q$LsuMNAROewyx.LomDtPpL9iJIOD3tsRThnzsAGE0hZXLMtdVCHVQ3pxzm3El8K2kuhcYLXJnhz.xUDGiE27s\/1\npwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty<\/pre>\n\n\n\n
[root@linuxcool ~]# awk -F: '{print $NF}' \/etc\/passwd<\/strong>\r\n\/bin\/bash\r\n\/sbin\/nologin\r\n\/sbin\/nologin\r\n\/sbin\/nologin\r\n\/sbin\/nologin\r\n\/bin\/sync\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n","protected":false},"excerpt":{"rendered":"