Solved

printing portion of a line after a pattern match

Posted on 2010-08-16
4
566 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:mgferg
4 Comments
 
LVL 2

Expert Comment

by:gosvald
ID: 33445432
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.
 
0
 
LVL 8

Accepted Solution

by:
mustaccio earned 25 total points
ID: 33446822
If you are OK with using perl, here's one way to do it:

perl -pn -e 's/^.*ID:(.*)$/$1/' yourinputfile
0
 

Author Comment

by:mgferg
ID: 33447590
-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"
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 25 total points
ID: 33448048
If not all lines contain a match for ID: you could use
perl -lne 'print $1 if /ID:(.*)/' yourinputfile
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now