Awk script to match pattern till blank line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk script to match pattern till blank line
# 1  
Old 11-19-2010
Question Awk script to match pattern till blank line

Hi,

I need to match lines after a pattern, upto the first blank line.
Searched in web and some forums but coulnt find the answer.


Code:
    where <restart_step> =
       10 -- Execute query 
       20 -- Write the contents to the Oracle table 
        30 -- Writing Contents to OUTPUT Directory

the number of steps may vary. I need to match the lines after <restart_step> .

Many Thanks
# 2  
Old 11-19-2010
try this,
Code:
awk 'BEGIN{RS="\n\n";FS="<restart_step> ="} { print $2}' inputfile

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 11-19-2010
MySQL

Hi pravin

The above code just displays 4 blank lines .

---------- Post updated at 01:39 AM ---------- Previous update was at 01:36 AM ----------

Pravin,


Thanks a ton! just changing to print$0 instead of $2 gives the desired output!

Code:
 
awk 'BEGIN{RS="\n\n";FS="<restart_step> ="} { print $0}'

# 4  
Old 11-19-2010
It works fine at my end
Code:
# cat testfile
where <restart_step> =
       10 -- Execute query
       20 -- Write the contents to the Oracle table
        30 -- Writing Contents to OUTPUT Directory

test
for you

Code:
#awk 'BEGIN{RS="\n\n";FS="<restart_step> ="} { print $2}' testfile

       10 -- Execute query
       20 -- Write the contents to the Oracle table
        30 -- Writing Contents to OUTPUT Directory

Could you please post your input file.
# 5  
Old 11-19-2010
Hii Pravin,

Code:
 
> cat file.txt
where <restart_step> =
       10 -- Execute query
       20 -- Write the contents to the Oracle table
        30 -- Writing Contents to OUTPUT Directory
test
for you
> awk 'BEGIN{RS="\n\n";FS="<restart_step> ="} { print $2}' file.txt
 
 
 
>

Am sorry there ws a mistake. The same code gives different output..
is there any other way to achieve this
# 6  
Old 11-19-2010
does this help..
Code:
sed '/<restart_step>/,/^$/!d' inputfile

This User Gave Thanks to michaelrozar17 For This Post:
# 7  
Old 11-19-2010
Code:
awk '!NF{p=0}p;/restart_step/{p=1}' infile

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script for pattern match and line break

Hi, I have input which reads like 9089.00 ----- kl jkjjljk lkkk; (909099) 9097.00 ----- HGJJHHJ jcxkjlkjvhvlk jhdkjksdfkhfskd 898.00 ----- HHHH I am trying to do something like this - As soon as I found pattern match "XYZ.00-----" it will insert a line break to the input and will go to... (3 Replies)
Discussion started by: Indra2011
3 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

Combine multiline to one line till a blank line

Hello, I have a file as :- ABC DEF GHI JKL <BlankLine> MNO PQR STU VWX <BlankLine> YZA I need it as below:- ABCDEFGHIJKL; MNOPQRSTUVWX; (3 Replies)
Discussion started by: jassi10781
3 Replies

4. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

5. Shell Programming and Scripting

Pattern match till the end of the file.

I have a file which is like this ……………………………………….. ………………………………… ………………………………… …………………………………… ……………………………………. ……………………………… <<<from_here>>> ……………………………… ………………………………. I want a script which would fetch the data starting from <<<from_here>>> in the file till the end... (2 Replies)
Discussion started by: halfafringe
2 Replies

6. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

8. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies

9. Shell Programming and Scripting

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS: SINGCORP invalid... (1 Reply)
Discussion started by: adityam
1 Replies

10. Post Here to Contact Site Administrators and Moderators

how to read a file till it encounters a blank line

Hi , I want to read a file starting with "*" up to till it encounters a blank line and to redirect this output to a different file.Plz suggest how to write a script for this. e.g:- * PK Sent Email (11.23) CALYPSO 1243215 9116457 NEW TRAD FAILED Nov 23 2007 9:34AM OASYS: DPS:... (0 Replies)
Discussion started by: adityam
0 Replies
Login or Register to Ask a Question