awk:display_line_after_the_matching_string
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
awk:display_line_after_the_matching_string [2020/09/23 16:12] – created 192.168.1.1 | awk:display_line_after_the_matching_string [2021/01/06 17:04] (current) – [AWK - Display line after the matching string] peter | ||
---|---|---|---|
Line 5: | Line 5: | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Example ====== | ||
+ | |||
+ | Assuming a file, **test.txt**, | ||
+ | |||
+ | < | ||
+ | 10 | ||
+ | 11 | ||
+ | 12 | ||
+ | 13 | ||
+ | 14 | ||
+ | 48 | ||
+ | </ | ||
+ | |||
+ | Running | ||
+ | |||
+ | <code bash> | ||
+ | awk '/ | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 11 | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | Running | ||
+ | |||
+ | <code bash> | ||
+ | awk '/ | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 11 | ||
+ | 13 | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | It then proceeds with row 12 which also contains the search string **Roux**, so it includes row 13 in the results. | ||
+ | |||
+ | No further rows contain the search string so nothing else is added to the result. | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | Running | ||
+ | |||
+ | <code bash> | ||
+ | awk '/ | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 11 | ||
+ | 14 | ||
+ | 48 | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | It then proceeds from row 12. It does not find the search string **4**, so moves to row 13. | ||
+ | |||
+ | In row 13 it finds the search string **4**, so it includes the next row 14 in the results; even though row 14 also contains the same search string. | ||
+ | |||
+ | It then proceeds from row 15. | ||
+ | |||
+ | The last row contains the search string; and as there is no other row below that can be added to the result; the last row itself is added. | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ---- |
awk/display_line_after_the_matching_string.1600877565.txt.gz · Last modified: 2020/09/23 16:12 by 192.168.1.1