I am looking to display the line 4598 in the following file. Effectively I want to display the line AFTER the nth occurrence of a match. In this case, the line after the 3rd occurrence of <Car>
. How do I go about this?
<Car>
10456
</Car>
<Car>
70192
</Car>
<Car>
4598
</Car>
Best Answer
Or:
To pass the search pattern as a variable:
Here using
ENVIRON
instead of-v
as-v
expands backslash-escape sequences and backslashes are often found in regular expressions (so would need to be doubled with-v
).GNU
awk
4.2 or above lets you assign variables as strong typed regexps. As long as its POSIX mode is not enabled (for instance via the$POSIXLY_CORRECT
environment variable, you can do: