How to give a pattern for new line in grep? New line at beginning, new line at end. Not the regular expression way. Something like \n.
To find a pattern that is more than one word long, enclose the string with single or double quotation marks. The grep command can search for a string in groups of files. When it finds a pattern that matches in more than one file, it prints the name of the file, followed by a colon, then the line matching the pattern.
-m 1 means return the first match in any given file. But it will still continue to search in other files. Also, if there are two or more matched in the same line, all of them will be displayed.
try pcregrep
instead of regular grep
:
pcregrep -M "pattern1.*\n.*pattern2" filename
the -M
option allows it to match across multiple lines, so you can search for newlines as \n
.
grep
patterns are matched against individual lines so there is no way for a pattern to match a newline found in the input.
However you can find empty lines like this:
grep '^$' file grep '^[[:space:]]*$' file # include white spaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With