Hold buffer in sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hold buffer in sed
# 1  
Old 02-05-2014
Hold buffer in sed

Hi Experts,

i have a file like below

Code:
****
table name is xyz
row count for previous day 10
row count for today 20
diff between previous and today 10
scan result PASSED
****
table name is abc
row count for previous day 90
row count for today 35
diff between previous and today 55
scan result FAILED
****
table name is def
row count for previous day 30
row count for today 10
diff between previous and today 20
scan result PASSED
****

My requirement is that i want to print block containing PASSED together like below output..

Code:
****
table name is xyz
row count for previous day 10
row count for today 20
diff between previous and today 10
scan result PASSED
****
table name is def
row count for previous day 30
row count for today 10
diff between previous and today 20
scan result PASSED
****

i tried like below but not getting proper result can you please help me in this?

Code:
sed -n '
'/PASSED/' !{ '/FAILED/'{
d
x
d
d
d
d
h
n
d
}
H
}
'/PASSED/' {
H
n
H
x
p
}' test_file

# 2  
Old 02-05-2014
You can try something like this with awk:
Code:
awk  '/PASSED/' RS=* ORS=**** file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 02-05-2014
If it needs to be a sed command, try:
Code:
sed -n '1h; 1!H; /FAILED/ {n;n;H;x;d}; /PASSED/ {n;H;x;p}' file

Works on the sample you provided in post #1.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 02-05-2014
Thats Great Rudic .. it worked !! I am not getting first portion of code just after sed -n and before /FAILED/ can you please explain?

Code:
 sed -n '
 1h
 1!H
 /FAILED/ {
 n
 n
 H
 x
 d
 }
 /PASSED/ {
 n
 H
 x
 p}' test_file

# 5  
Old 02-05-2014
It puts the first line to the hold buffer; all other lines will be appended... if you append the first line as well as the others, there will be an empty line at the beginning.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed's hold-space to filter file contents

I wrote an awk script to filter "uninteresting" commands from my ~/.bash_history (I know about HISTIGNORE, but I don't want to exclude these commands from my current session's history, I just want to avoid persisting them across sessions). The history file can contain multi-line entries with... (6 Replies)
Discussion started by: ivanbrennan
6 Replies

2. Shell Programming and Scripting

read is not on hold

In end of https://www.unix.com/shell-programming-scripting/103227-while-read-loop-scope-variables-shell.html mjd_tech gives script which can read some values directly without manually input, but if no value is the right one, my understand is, it will on hold for waiting the next input, but when I... (7 Replies)
Discussion started by: newoz
7 Replies

3. Shell Programming and Scripting

Hold, Replace and Print with sed

Hi, I'm a newbie with scripting so I'd appreciate any help. I have a file import.txt with below text AA_IDNo=IDNoHere AA_Name=NameHere AA_Address=AddressHere AA_Telephone=TelephoneHere AA_Sex=SexHere AA_Birthday=BirthdayHere What I need is that the Lines for Name, Address and... (3 Replies)
Discussion started by: heretolearn
3 Replies

4. Shell Programming and Scripting

Hold buffer in perl

Hi, Can any one tell me is their any "hold buffer" in perl similar to sed. I have to find a pattern, once that pattern found then need to go backward and find another pattern and print. Example: Below are the contents present in a file ## block IPs URLs URL_IPs Unblock URLs ... (4 Replies)
Discussion started by: Anjan1
4 Replies

5. Shell Programming and Scripting

sed: hold buffer question

I've been using sed to help with reformatting some html content into latex slides using the beamer class. Since I'm new to sed, I've been reading a lot about it but I'm stuck on this one problem. I have text that looks like this: ******************* line of text that needs to be... (4 Replies)
Discussion started by: tfrei
4 Replies

6. Shell Programming and Scripting

sed pattern and hold space issues

Good day. Trying to make a sed script to take text file in a certain format and turn it into mostly formatted html. I'm 95% there but this last bit is hurting my head finally. Here's a portion of the text- Budgeting and Debt: Consumer Credit Counseling of Western PA CareerLink 112... (5 Replies)
Discussion started by: fiendracer
5 Replies

7. Shell Programming and Scripting

Hold previous date

A file named abc.txt being updated with date value by one process. Say , today it s updating the file with value 01-09-2009 Fine. Tomorrow the process will override the file with tomorrow date (02-09-2009) .Insome case the process will overriding the file with empty string. So I... (1 Reply)
Discussion started by: Gopal_Engg
1 Replies

8. Shell Programming and Scripting

injecting new line in sed substitution (hold space)

Morning, people! I'd like to call upon your expertise again, this time for a sed endeavor. I've already searched around the forums, didn't find anything that helped yet. background: Solaris 9.x, it's a closed system and there are restrictions to what is portable to it. So let's assume I... (4 Replies)
Discussion started by: ProGrammar
4 Replies

9. Shell Programming and Scripting

Using sed buffer

Hi. I have some questions about using sed. I cannot use the hold buffer. For example i want to put first line to the buffer than take second line and append the buffer to the second line.then 3th to the all. It will be like 2->1->3 th lines. Any idea? (1 Reply)
Discussion started by: burakkilic
1 Replies

10. UNIX for Dummies Questions & Answers

Support Needed: Education On Hold

I'm Presently Writting A College Report On Operating Systems, Not Enjoying It Very Much. I Was Hoping Someone Could Direct Me To A Site Where I Could Get Information Such As The Role Of Operating Systems, Types Of Operating Systems (Multi-User Multi-Tasking etc), Modes Of Operating systems... (3 Replies)
Discussion started by: OSNovice
3 Replies
Login or Register to Ask a Question