1834016 Members
2405 Online
110063 Solutions
New Discussion

mulit line pattern?

 
SOLVED
Go to solution
Jack_27
Advisor

mulit line pattern?

Hi,guys

I need extract the complete line from the file as below: (example.dat)
...
abc=123 456 FFF 789 HHH 000 KKK
...

Only the "abc=123 456 FFF \" could be gotten with " grep abe example.dat" but the rest part were lost.

Could we use the normal script to handle such cases?

Thanks
Jack
7 REPLIES 7
Jack_27
Advisor

Re: mulit line pattern?

Notice:
The "FFF" and "HHH" were followed by the "\" character.
LE_1
Advisor

Re: mulit line pattern?

Can you try "cat -v example.dat | grep abc" ?
Jack_27
Advisor

Re: mulit line pattern?

Hi,LE

It does't work well.
Robin Wakefield
Honored Contributor

Re: mulit line pattern?

Hi Jack,

Can you attach the file - not sure what you mean by the "\" character, as that should grep with no problems.

rgds, Robin
Francisco J. Soler
Honored Contributor
Solution

Re: mulit line pattern?

Hi, Jack
I have found a solution something "twisted"

Issue the command:
awk -f script.awk example.dat

I have attached the file script.awk.

hope this helps.
Frank.
Linux?. Yes, of course.
Jack_27
Advisor

Re: mulit line pattern?

Hi,Frank

Wonderful!The awk script you provided works well.
The output was :
abc 123 456 FFF 789 HHH 000 KKK UUU

Robin,
I've attached the example.dat and please review it.

Thank all of you!

Cheers
Jack
Robin Wakefield
Honored Contributor

Re: mulit line pattern?

Hi Jack,

Here's a perl script to "grep" with continuation characters:

===============
#!/usr/bin/perl
$string=shift;
open FH,shift;
while (defined($line=)){
chomp $line;
if ($line=~s/\\\s*$//){
$line.=;
redo unless eof(FH);
}
print "$line\n" if ($line=~/$string/);
}
================

so to run it:

% scriptname searchstring filename

rgds, Robin