5
2
How can I search a text file for this pattern in Ubuntu terminal and save the output as a text file?
I'm looking for everything between the string "abc" and the string "cde" in a long list of data.
For example:
blah blah abc fkdljgn cde blah
blah blah blah blah blah abc skdjfn cde blah
In the example above I would be looking for an output such as this:
fkdljgn
skdjfn
It is important that I can also save the data output as a text file.
Can I use grep or agrep and if so, what is the format?
I'm not sure your original grep pattern matches all of the other patterns you use. '.*(?=cde)' matches chars then 'cde', but '(.+) cde' matches chars, then a space, then 'cde'. – Octavia Togami – 2014-06-04T16:21:05.957
@KenzieTogami yes indeed, the
grep
one will have a trailing space. I realized after posting the grep one that the OP probably doesn't want the spaces so I removed them from the alternatives and forgot to do so in thegrep
. Thanks, I fixed it now. – terdon – 2014-06-04T16:28:59.653