Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print everything on line after match [duplicate]

Tags:

grep

bash

I have an large textfile that contains an unique string in the middle. What i want to do is 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?

like image 585
twk789 Avatar asked Mar 18 '11 00:03

twk789


2 Answers

Strangely, the accepted answer printed out the whole line, where I just wanted all the info after the target string. This worked for me:

sed -n 's/target_string//p' filename 

Adapted from this post

like image 156
chimeric Avatar answered Oct 13 '22 00:10

chimeric


With GNU grep, try -B0 -A999999999 or similar. A better choice might be awk:

awk '/target_string/ {seen = 1}      seen            {print}' 

If (your problem specification is slightly unclear) you don't also need to print the matching line, sed is even shorter:

sed '1,/target_string/d' 
like image 35
geekosaur Avatar answered Oct 12 '22 22:10

geekosaur