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

How to use the next command of awk

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how to use the next command of awk. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

To understand how it works, let's analyze food_list.txt, which looks like this:

Food List ItemsNo Item_Name Price Quantity1 Mangoes $3.4552 Apples $2.45253 Pineapples $4.45554 Tomatoes $3.45255 Onions $1 .45156 Bananas $3.4530 >

Run the following command, which will mark each line with an asterisk after the number of food is less than or equal to 20:

# awk'$4 20 {print $0;} 'food_list.txt No Item_Name Price Quantity1 Mangoes $3.45 5 * 2 Apples $2.45 253 Pineapples $4.45 554 Tomatoes $3.45 25 5 Onions $1.45 15 * 6 Bananas $3.45 30

The above command actually runs as follows:

1. It uses the $4 20 expression to check whether the fourth column of each input line is greater than 20, and displays it if the condition is met.

But there is a problem. When the first expression is marked with the {printf "% s/t%s/n", $0, "* *";} command, the second expression is judged at the same step, which is a waste of time. So when we have printed the flag line with the first expression, we no longer need to print it again with the second expression $4 > 20.

To deal with this, we need to use the next command:

# awk'$4 20 {print $0;} 'food_list.txt

When the input line uses the $4 20 {print $0;} expression, proceed to determine the next input line instead of wasting time continuing to determine whether the current input line is still greater than 20.

The next command is very important when writing efficient command scripts, which can improve the speed of the script.

This is the end of this article on "how to use the next command of awk". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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