User Tools

Site Tools


awk:display_line_after_the_matching_string

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
awk:display_line_after_the_matching_string [2020/09/23 16:12] – created 192.168.1.1awk:display_line_after_the_matching_string [2021/01/06 17:04] (current) – [AWK - Display line after the matching string] peter
Line 5: Line 5:
 </code> </code>
  
 +
 +----
 +
 +====== Example ======
 +
 +Assuming a file, **test.txt**, exists with the following contents:
 +
 +<file>
 +10   Peter     Terence   Roux        45
 +11   Virginia  Genevieve  Roux        45
 +12   Felix     Devon     Roux         5
 +13   David     Bruce     Stevenson   48
 +14   Bob       James     Smith       16
 +48   Adam      Winter    Ridley      23
 +</file>
 +
 +Running
 +
 +<code bash>
 +awk '/Peter/{getline; print}' test.txt
 +</code>
 +
 +returns:
 +
 +<code bash>
 +11   Virginia  Genevive  Roux        45
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  This simply returns the next line after the search string of **Peter**.
 +</WRAP>
 +
 +
 +----
 +
 +Running
 +
 +<code bash>
 +awk '/Roux/{getline; print}' test.txt
 +</code>
 +
 +returns:
 +
 +<code bash>
 +11   Virginia  Genevieve  Roux       45
 +13   David     Bruce     Stevenson   48
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  This finds the search string **Roux** in row 10, so it includes the next row 11 in the result; even though row 11 also contains the same search string.
 +
 +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.
 +</WRAP>
 +
 +
 +----
 +
 +Running
 +
 +<code bash>
 +awk '/4/{getline; print}' test.txt
 +</code>
 +
 +returns:
 +
 +<code bash>
 +11   Virginia  Genevieve  Roux       45
 +14   Bob       James     Smith       16
 +48   Adam      Winter    Ridley      23
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  This finds the search string **4** in row 10, so it includes the next row 11 in the result; even though row 11 also contains the same search string.
 +
 +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.  Possibly a bug?
 +</WRAP>
 +
 +
 +
 +----
awk/display_line_after_the_matching_string.1600877565.txt.gz · Last modified: 2020/09/23 16:12 by 192.168.1.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki