Reputation: 1246
Trying to figure out how to write a command across multiple lines because the real one is way to long for a prompt (4200 chars), so I tried this example:
Made a test file that contained the following 3 lines:
some thing
some
thing
When I do this grep:grep "some thing" test
I get the expected result of:some thing
But when I do this grep: grep "some \
thing" test
I get the unexpected result of:
some thing
thing
Almost as if it ran the grep twice, once for "some " and once for "thing". Is there any way to properly use the \
to combine the 2 to where the result is like the first grep?
Upvotes: 0
Views: 1554
Reputation: 5337
Using -zPo you can make grep behave multilingual:
grep -zPo 'some\nthing' test
Upvotes: 1
Reputation: 1246
So it looks like this did it:
grep "some \
|thing" test.txt
Produced: some thing
Same as: grep "some thing" test.txt
Upvotes: 0
Reputation: 597
Instead of grep, you have to use pcregrep, then you will be able to use new lines in pattern by -M option.
In your example it will be like:
pcregrep -M 'some\nthing' test
Upvotes: 3