当前位置:网站首页>Awk from entry to soil (5) simple condition matching

Awk from entry to soil (5) simple condition matching

2022-07-04 08:46:00 Wonderful binary

We have been talking about ,awk The usage syntax of is as follows ( I think you are already familiar with ):

awk [options] ‘pattern {Action}’ file1 file2 ···

about options( Options ) for , We used it -F Options , Also used -v Options .

about Action( action ) for , We used it print And printf, Later in the article , We will also be right Action Summarize .

about Pattern( Pattern ) for , We are just beginning to learn awk when , Two special modes are introduced ,BEGIN Patterns and END Pattern , however , We don't have a detailed introduction ” Pattern ” What is it? , How to use it? , And here , We will introduce in detail awk The pattern in .

“ Pattern ” This word sounds very literary , It's not particularly easy to understand , Let's put it another way , We put ” Pattern ” Switch to ” Conditions ”, Maybe easier to understand , that ” Conditions ” What does that mean ? We know ,awk It processes text line by line , in other words ,awk Will deal with the current line first , Process the next line , If we don't specify any ” Conditions ”,awk Each line in the text will be processed line by line , If we specify ” Conditions ”, Only satisfaction ” Conditions ” The row will be processed , dissatisfaction ” Conditions ” The row will not be processed . Is that a little easier to understand than just now ? This is actually awk Medium ” Pattern ”.

Again , When awk When processing line by line , Will be able to pattern( Pattern ) As a condition , Judge whether the row to be processed meets the conditions , Can you follow ” Pattern ” Match , If the match , Then deal with , If it doesn't match , Do not deal with .

Take a small example &

原网站

版权声明
本文为[Wonderful binary]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040838047397.html