I am trying to look for patterns in a file. The looks like this:
aaa;
bbb;
If I try the following it does not stop:
cat test | tr -d '\n' | ack -1 'aa.*;'
aaa;bbb;
Is there a way to stop with aaa;
?
I am trying to look for patterns in a file. The looks like this:
aaa;
bbb;
If I try the following it does not stop:
cat test | tr -d '\n' | ack -1 'aa.*;'
aaa;bbb;
Is there a way to stop with aaa;
?
Your regex is greedy, so it includes all text after the second a
until the final semi-colon. If you refine the pattern to NOT be greedy (with a question mark) and use the -o option, you'll get what you expect:
$cat test.txt | tr -d '\n' | ack -o 'aa.*?;'
aaa;
See more recipes/details here