I have a text file in this format [ONE testing 1 2 3] [TWO lorem ipsum] [ONE 123]
I want to print `[ONE.+]` line by line.
An example output would be
[ONE testing 1 2 3]
[ONE 123]
I’ve tried awk '/\[ONE.+\]/ { print $1 }' but it didn’t work. Can anyone teach me why? And what the correct way is?
awk works line by line, so the expression is only matched once per line. To do it in awk, you can use the
matchfunction in a loop. You’d also have to modify your regex to be less greedy, since your expression doesn’t magically stop at the first ].It might be easier to just use grep: