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
.
More Related Contents:
- how does the bash command "grep -v ":0"" work
- How can I manipulate text in bash? [closed]
- Echo newline in Bash prints literal \n
- How can I pipe stderr, and not stdout?
- ‘\r’: command not found – .bashrc / .bash_profile [duplicate]
- How to merge every two lines into one from the command line?
- Fast way of finding lines in one file that are not in another?
- Capturing Groups From a Grep RegEx
- How to avoid bash command substitution to remove the newline character?
- How to get the part of a file after the first line that matches a regular expression
- Is there an easy way to pass a “raw” string to grep?
- How to process each output line in a loop?
- Checking if output of a command contains a certain string in a shell script
- Colorized grep — viewing the entire file with highlighted matches
- How to check if a file contains a specific string using Bash
- Bash: Strip trailing linebreak from output
- Piping tail output though grep twice
- Check if all of multiple strings or regexes exist in a file
- Grepping a huge file (80GB) any way to speed it up?
- Bash script – “/bin/bash^M: bad interpreter: No such file or directory” [duplicate]
- Fastest possible grep
- Waiting for background processes to finish before exiting script
- How do you search for files containing DOS line endings (CRLF) with grep on Linux?
- How to use `while read` (Bash) to read the last line in a file if there’s no newline at the end of the file?
- Prevent grep returning an error when input doesn’t match
- Grep output with multiple Colors?
- Using grep to search for hex strings in a file
- How to strip out all of the links of an HTML file in Bash or grep or batch and store them in a text file
- How to delete rows from a csv file based on a list values from another file?
- How to grep for case insensitive string in a file?