grepping multiple matches in a single string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grepping multiple matches in a single string
# 1  
Old 02-29-2012
grepping multiple matches in a single string

Hi All,

I'm trying to grep for 3 patterns in a string of gibberish. It so happens that each line is appended by a date/time stamp and i was able to figure out how to extract only the datetime.

here is the string..

Quote:
[$blah.blah.blah.tinker.blah.blah.tailor blah.solider.$[blah.spy
i have to display

Code:
tinker tailor soldier spy

Please can some help me in acheiving this.

Cheers
Irishiboy

Last edited by methyl; 02-29-2012 at 07:40 PM..
# 2  
Old 02-29-2012
I fear you may have oversimplified the text to be parsed. I'll write something that works to this text, but if it doesn't work for your text, you will need to post something less obscured.

grep matches lines. try awk, which is grep-like but an entire language...

Code:
awk -F. '{ split($7, A, " ); print $4, A[1], $8, $10 }' inputfile

# 3  
Old 02-29-2012
There is no sensible way to approach this because there is no proper record structure.
At first glance you have fields delimited by "." ... except the one containing "tailor".

In the future please post "real world" problems from your commercial environment.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

2. Shell Programming and Scripting

Grepping only if condition matches

Dear Friends, I have a flat file which is as follows $cat sample 123,456,1,1,1,1 sdfas,345,1,1,1,1 dfgd,234,2,3,4,1 ggffgr,234,4,3,2,1 jkhu,354.1,1,1,1 $ I want to get output of only those lines which has '1' in 3 to 5 position. So I want output as follows 123,456,1,1,1,1... (8 Replies)
Discussion started by: anushree.a
8 Replies

3. Shell Programming and Scripting

Find multiple strings and replace single string

Hi, following Perl code i used for finding multiple strings and replace with single string. code: #!/usr/bin/perl my @files = <*.txt>; foreach $fileName (@files) { print "$fileName\n"; my $searchStr = ',rdata\)' | ',,rdata\)' | ', ,rdata\)'; my $replaceStr =... (2 Replies)
Discussion started by: chettyravi
2 Replies

4. Shell Programming and Scripting

Multiple search strings replaced with single string

Hi, I need someone's help in writing correct perl code. I implemented following code for "multiple search strings replaced with single string". ========================================================= #!/usr/bin/perl my $searchStr = 'register_inst\.write_t\(' |... (2 Replies)
Discussion started by: chettyravi
2 Replies

5. Shell Programming and Scripting

How to merge multiple rows into single row if first column matches ?

Hi, Can anyone suggest quick way to get desired output? Sample input file content: A 12 9 A -0.3 2.3 B 1.0 -4 C 34 1000 C -111 900 C 99 0.09 Output required: A 12 9 -0.3 2.3 B 1.0 -4 C 34 1000 -111 900 99 0.09 Thanks (3 Replies)
Discussion started by: cbm_000
3 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Shell Programming and Scripting

SED - Multiple String - Single Line

Would appear to me to be a farily simple question but having search all the threads I can't find the answer .. I just want sed to output the single line in a file that contains two string anywhere on the line.. e.g. currently using this command sed -n -e'/str1/p' -e '/str2/p' < file and... (3 Replies)
Discussion started by: flopster
3 Replies

8. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

9. Shell Programming and Scripting

Grepping string from out file

Guys .. Need to pull this highlighted strings irrespective of line numbers & should be echoed . But these strings are from Outfile from different dir. In which way this can be grepped ?? Need an idea http-timeout 120 seconds persistent-timeout 180 seconds host-rewriting on ... (7 Replies)
Discussion started by: raghunsi
7 Replies

10. Shell Programming and Scripting

Grepping using multiple wildcards

Is there anyway you can grep using multiple wildcards? When I run the below line the results return fine; grep 12345 /usr/local/production/soccermatchplus/distributor/clients/*/out/fixtures.xml | awk -F/ '{print $8}' However ideally, I need it to grep for; grep 12345... (3 Replies)
Discussion started by: JayC89
3 Replies
Login or Register to Ask a Question