{"id":22922,"date":"2023-07-29T17:58:14","date_gmt":"2023-07-29T09:58:14","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=22922"},"modified":"2023-07-29T17:58:14","modified_gmt":"2023-07-29T09:58:14","slug":"awk-comparison-operator","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/awk-comparison-operator.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528awk\u7684\u6bd4\u8f83\u64cd\u4f5c\u7b26"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5bf9\u4e8e\u4f7f\u7528 awk \u547d\u4ee4\u7684\u7528\u6237\u6765\u8bf4\uff0c\u5904\u7406\u4e00\u884c\u6587\u672c\u4e2d\u7684\u6570\u5b57\u6216\u8005\u5b57\u7b26\u4e32\u65f6\uff0c\u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\u6765\u8fc7\u6ee4\u6587\u672c\u548c\u5b57\u7b26\u4e32\u662f\u5341\u5206\u65b9\u4fbf\u7684\u3002\u4e0b\u9762\u7684\u90e8\u5206\u6211\u4eec\u4ecb\u7ecd\"awk\"\u7684\u6bd4\u8f83\u8fd0\u7b97\u7b26\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
awk \u4e2d\u7684\u6bd4\u8f83\u8fd0\u7b97\u7b26\u662f\u4ec0\u4e48\uff1f<\/strong><\/div>\n

awk \u4e2d\u7684\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u5b57\u7b26\u4e32\u548c\u6216\u8005\u6570\u503c\uff0c\u5305\u62ec\u4ee5\u4e0b\u7c7b\u578b\uff1a<\/p>\n\n\n\n\n\n\n\n\n\n\n\n
\u00a0<\/caption>\n
\u7b26\u53f7<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
><\/td>\n\u5927\u4e8e<\/td>\n<\/tr>\n
<<\/td>\n\u5c0f\u4e8e<\/td>\n<\/tr>\n
>=<\/td>\n\u5927\u4e8e\u7b49\u4e8e<\/td>\n<\/tr>\n
<=<\/td>\n\u5c0f\u4e8e\u7b49\u4e8e<\/td>\n<\/tr>\n
==<\/td>\n\u7b49\u4e8e<\/td>\n<\/tr>\n
!=<\/td>\n\u4e0d\u7b49\u4e8e<\/td>\n<\/tr>\n
some_value ~ \/ pattern\/<\/td>\n\u5982\u679c some_value \u5339\u914d\u6a21\u5f0f pattern\uff0c\u5219\u8fd4\u56de true<\/td>\n<\/tr>\n
some_value !~ \/ pattern\/<\/td>\n\u5982\u679c some_value \u4e0d\u5339\u914d\u6a21\u5f0f pattern\uff0c\u5219\u8fd4\u56de true<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u73b0\u5728\u6211\u4eec\u901a\u8fc7\u4f8b\u5b50\u6765\u719f\u6089 awk \u4e2d\u5404\u79cd\u4e0d\u540c\u7684\u6bd4\u8f83\u8fd0\u7b97\u7b26\u3002<\/p>\n

\u4f8b\u5b50\u4e00\uff0c\u6211\u4eec\u6709\u4e00\u4e2a\u6587\u4ef6\u540d\u4e3a food_list.txt \u7684\u6587\u4ef6\uff0c\u91cc\u9762\u5305\u62ec\u4e0d\u540c\u98df\u7269\u7684\u8d2d\u4e70\u5217\u8868\u3002\u6211\u60f3\u7ed9\u98df\u7269\u6570\u91cf\u5c0f\u4e8e\u6216\u7b49\u4e8e 30 \u7684\u7269\u54c1\u6240\u5728\u884c\u7684\u540e\u9762\u52a0\u4e0a (**)<\/p>\n

 File \u2013 food_list.txt\r\nNo      Item_Name               Quantity        Price\r\n1       Mangoes                    45           $3.45\r\n2       Apples                     25           $2.45\r\n3       Pineapples                 5            $4.45\r\n4       Tomatoes                   25           $3.45\r\n5       Onions                     15           $1.45\r\n6       Bananas                    30           $3.45\r\n<\/pre>\n

Awk \u4e2d\u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7684\u901a\u7528\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n

 # \u8868\u8fbe\u5f0f { \u52a8\u4f5c; }<\/pre>\n

\u4e3a\u4e86\u5b9e\u73b0\u521a\u624d\u7684\u76ee\u7684\uff0c\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n

 # awk '$3 <= 30 { printf \"%s\/t%s\/n\", $0,\"**\" ; } $3 > 30 { print $0 ;}' food_list.txt\r\n\r\nNo  Item_Name`      Quantity    Price\r\n1   Mangoes            45       $3.45\r\n2   Apples             25       $2.45   **\r\n3   Pineapples         5        $4.45   **\r\n4   Tomatoes           25       $3.45   **\r\n5   Onions             15       $1.45   **\r\n6   Bananas            30       $3.45   **\r\n<\/pre>\n

\u5728\u521a\u624d\u7684\u4f8b\u5b50\u4e2d\uff0c\u53d1\u751f\u5982\u4e0b\u4e24\u4ef6\u91cd\u8981\u7684\u4e8b\u60c5\uff1a<\/p>\n