Link to home
Start Free TrialLog in
Avatar of mgferg
mgferg

asked on

printing portion of a line after a pattern match

Hi, I have a number of lines which I need to extract only the portion of the line after a pattern match is found

e.g.

2010-08-16 11:34:57,869 text: text: ....text ID: rest of line

so I want to only show "rest of line" based on it finding a match for "ID:"
(note there coud be a different number of ":" preceeding the pattern to match "ID:")

This is to be used in a Solaris 10 shell script and probably using something like awk, but can't find out how to do this

Thanks
Mark
Avatar of gosvald
gosvald

You can use grep command for this. It should be available on Solaris. You can specify how many lines you want to see as well. If you do not use any extra options it will just give you the line where it found the pattern.
The syntax is:

grep [options] PATTERN [FILE...]
or
grep [options] [-e PATTERN | -f FILE] [FILE...]

So  in you case:

grep -R ID *

this will search for ID in all files. If you want to find out more just read the grep man file.
 
ASKER CERTIFIED SOLUTION
Avatar of mustaccio
mustaccio
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mgferg

ASKER

-R seems to be an invalid option

and note I don't want the full line - I'm using grep to get that already - I only want portion of the line "after" a "pattern match"
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial