Search code examples
bashgrep

Print everything on line after match


I have a large text file that contains a unique string in the middle. I want to print everything AFTER the string by using grep.

cat textfile | grep "target_string"
This highlights target_string but prints the whole file

cat textfile | grep -o "target_string"
This prints only target_string

cat textfile | grep -o "target_string*"
This prints only target_string

How can I print everything after "target_string" and nothing before?


Solution

  • You forgot the '.' in the regular expression:

    cat textfile | grep -o "target_string.*"