multiple search separated by blank line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple search separated by blank line
# 1  
Old 12-21-2008
multiple search separated by blank line

hi all

I want to get multiple search that are separated by blank line according to first search in text file

eg: egrep 'x|Y|Z' file


in that for each x...it should be seperated by blank line


will u pls help
# 2  
Old 12-22-2008
grep -B 1 ^$ | egrep 'x|Y|Z' file

^$ for blank line and -B 1 prints blank line and before line
# 3  
Old 12-22-2008
multiple search separated by blank line

I am not getting pls help


Quote:
Originally Posted by suryanarayana
hi all

I want to get multiple search that are separated by blank line according to first search in text file

eg: egrep 'x|Y|Z' file


in that for each x...it should be seperated by blank line


will u pls help
# 4  
Old 12-22-2008
sorry command is

grep -B 1 ^$ file | egrep 'x|Y|Z'

can u post sample data
# 5  
Old 12-22-2008
cat list
DELETE:MD:TM,432350214576013;

RESP:940120105;
DELETE:MD:TM,432350415547447;

RESP:940120105;

SET:NOK:TM,432350110811018:T22,0;

RESP:11000999;
SET:MD:TM,4323500223734641;

RESP:0;
SET:NOK:TM,432350220813251:BAIC,1;
RESP:0;



SET:MD:TM,4323502142003351;

RESP:0;
DELETE:MD:TM,432350415283715;

RESP:0;
DELETE:MD:TM,432350415434001;

RESP:0;
SET:MD:TRIM,989370025055:LANG,English;
RESP:0;



DELETE:MD:TM,432350041977269:TRIM,989371036084;;

RESP:940120105;
SET:MD:TM,432350214483040;

RESP:0;
DELETE:MD:TM,432350021443483:TRIM,989362585071;

RESP:0;


grep -B 1 ^$ list | egrep 'DELETE|SET'
DELETE:MD:TM,432350214576013;
DELETE:MD:TM,432350415547447;
SET:NOK:TM,432350110811018:T22,0;
SET:MD:TM,4323500223734641;
SET:MD:TM,4323502142003351;
DELETE:MD:TM,432350415283715;
DELETE:MD:TM,432350415434001;
DELETE:MD:TM,432350041977269:TRIM,989371036084;;
SET:MD:TM,432350214483040;
DELETE:MD:TM,432350021443483:TRIM,989362585071;
# 6  
Old 12-22-2008
multiple search separated by blank line

Pls examine this...
grep -B 1 ^$ | egrep 'Enter|@|SQL RUN' dat

Enter value for authid: 560000
SQL RUN TIME--- 22-12-2008 13:57:29
@lienup.sql SELECTED VALUE
Enter value for authid: 560000
SQL RUN TIME--- 22-12-2008 13:57:29
@lienup.sql SELECTED VALUE
...........................................


before.....every first one (ie Enter valur for authid ..)
i should get blank line

thx in advance


Quote:
Originally Posted by reddyrajal
sorry command is

grep -B 1 ^$ file | egrep 'x|Y|Z'

can u post sample data
# 7  
Old 12-22-2008
cat file

Enter value for authid: 560000
SQL RUN TIME--- 22-12-2008 13:57:29
@lienup.sql SELECTED VALUE
Enter value for authid: 560000
SQL RUN TIME--- 22-12-2008 13:57:29
@lienup.sql SELECTED VALUE

Enter value for authid: 560001
SQL RUN TIME--- 22-12-2008 13:57:30
@lienup.sql SELECTED VALUE
Enter value for authid: 560001
SQL RUN TIME--- 22-12-2008 13:57:30
@lienup.sql SELECTED VALUE


Enter value for authid: 560002
SQL RUN TIME--- 22-12-2008 13:57:40
@lienup.sql SELECTED VALUE
Enter value for authid: 560002
SQL RUN TIME--- 22-12-2008 13:57:40
@lienup.sql SELECTED VALUE


Enter value for authid: 560003
SQL RUN TIME--- 22-12-2008 13:57:50
@lienup.sql SELECTED VALUE
Enter value for authid: 560003
SQL RUN TIME--- 22-12-2008 13:57:50
@lienup.sql SELECTED VALUE



grep -A 3 ^$ file | egrep 'Enter|SQL RUN|@'
Enter value for authid: 560000
SQL RUN TIME--- 22-12-2008 13:57:29
@lienup.sql SELECTED VALUE
Enter value for authid: 560001
SQL RUN TIME--- 22-12-2008 13:57:30
@lienup.sql SELECTED VALUE
Enter value for authid: 560002
SQL RUN TIME--- 22-12-2008 13:57:40
@lienup.sql SELECTED VALUE
Enter value for authid: 560003
SQL RUN TIME--- 22-12-2008 13:57:50
@lienup.sql SELECTED VALUE


or try this grep -A 10 ^$ file | egrep -m 3 'Enter|SQL RUN|@'

Last edited by reddyrajal; 12-23-2008 at 02:58 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies

2. UNIX for Dummies Questions & Answers

How to delete blank line/s before and after a search pattern?

Hi, Test file x.txt below. This file is generated by a program that I unfortunately do not have control on how it gets presented/generated. create PACKAGE "XXX_INTERFACE_DEFECT_RPT_TEST" is TYPE refCursor IS REF CURSOR; Function queryRecords ( p_status varchar2, ... ... ... )... (4 Replies)
Discussion started by: newbie_01
4 Replies

3. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

4. Shell Programming and Scripting

Combining multiple block of lines in one comma separated line

Hi Everyone, On my Linux box I have a text file having block of few lines and this block lines separated by one blank line. I would like to format and print these lines in such a way that this entire block of lines will come as single comma separated line & again next block of lines in next... (7 Replies)
Discussion started by: gr8_usk
7 Replies

5. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

6. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

7. Shell Programming and Scripting

Need to remove a selection of rows separated by blank lines

hello, here is an example: 9.07 9.05 0.00 2.28 0.00 0.08 1.93 3.62 10.97 12.03 12.03 0.00 2.73 0.00 0.07 (3 Replies)
Discussion started by: Baron1
3 Replies

8. Shell Programming and Scripting

Text file to CSV with field data separated by blank lines

Hello, I have some data in a text file where fields are separated by blank lines. There are only 6 fields however some fields have several lines of data as I will explain. Also data in a particular field is not consistently the same size but does end on a blank line. The first field start with... (6 Replies)
Discussion started by: vestport
6 Replies

9. Shell Programming and Scripting

how to append blank line in multiple files in unix

Dear All- Please suggest a single unix command which can append blank line in multiple files. I need to achieve this using a single unix command and not a script Please do advice Regards, Suresh (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

10. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies
Login or Register to Ask a Question