adding another field to SED output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding another field to SED output
# 1  
Old 11-05-2009
adding another field to SED output

Dear experts,

I have a file called "check" with contents like below

Quote:
KPG-HF4-3
04/11/2009 03:15 InsertSubData
success failed
17752 6
6 Timeout
i used the sed command like below to get the value of "success" and "failed" only

Quote:
sed -n -e '/KPG-HF4-3/{ p; n; p; n; p; n; p; n;}' check | tail -1 | awk {'print $1,$2'}

17752 6
My question is how can i get the value to include the time "03:15", so that i can get a value such as below : -

Quote:
03:15 17752 6
Appreciate any advice. Thanks.
# 2  
Old 11-05-2009
Using awk:
Code:
awk '/[0-9]:[0-9]/ { TIME=$2 }/success/ { getline; print TIME, $0; exit }' file

# 3  
Old 11-05-2009
Thanks scottn.
your answer actually works, but maybe i was not very clear with my file. Apologies.

My complete file actually has an input like below

Quote:
RWG-HF4-1
04/11/2009 03:15 InsertSubData
success failed
21267 3
3 Timeout





NLI-HF4-2
04/11/2009 03:15 InsertSubData
success failed
17872 1
1 Timeout




KPG-HF4-3
04/11/2009 03:15 InsertSubData
success failed
17752 6
6 Timeout




RWG-HF4-4
04/11/2009 03:15 InsertSubData
success failed
21587 3
3 Timeout





NLI-HF4-5
04/11/2009 03:15 InsertSubData
success failed
17905 4
4 Timeout

How can i be sure that i am getting the outout for KPG-HF4-3 only?
Pls advice
# 4  
Old 11-05-2009
Quote:
Originally Posted by aismann
How can i be sure that i am getting the outout for KPG-HF4-3 only?
Pls advice
Code:
awk '/KPG-HF4-3/{getline;s=$2;getline;getline;print s $0;exit}' file

# 5  
Old 11-05-2009
Thank you franklin Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Combine Similar Output from the 2nd field w.r.t 1st Field

Hi, For example: I have: HostA,XYZ HostB,XYZ HostC,ABC I would like the output to be: HostA,HostB: XYZ HostC:ABC How can I achieve this? So far what I though of is: (1 Reply)
Discussion started by: alvinoo
1 Replies

2. Shell Programming and Scripting

Adding field to file

Hi I have file as given below 040|14300|40.0|563000 042|13200000|40.0 041|100|40.0 043|10000|40.0 045|102|40.0 I want to check if field 4 is null then I have to place | in position 4. result set should be 040|14300|40.0|563000 042|13200000|40.0| 041|100|40.0| 043|10000|40.0|... (9 Replies)
Discussion started by: shabeena
9 Replies

3. Shell Programming and Scripting

sed : Second field not getting displayed in the output

Hi , I have a file (input.txt) with the below contents : 20150223T12:00:25 hostnamex 20150716T10:40:54 hostnamey 20150202T20:08:03 hostnamez I want the output to be like below i.e excluding the timestamp ( THH:MM:SS) in the above file as follows : 20150223 hostnamex 20150716... (2 Replies)
Discussion started by: rahul2662
2 Replies

4. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Adding matching field

I have a flat file test.log red,5,,,,, green,7,,,,, blue,4,,,,, red,8,,,,, green,9,,,,, How i get a a result: blue,4,,,,, green,16,,,,, red,13,,,,, Thanks Video tutorial on how to use code tags in The UNIX and Linux Forums. (2 Replies)
Discussion started by: sabercats
2 Replies

7. Shell Programming and Scripting

Adding total of first field for each number in the second field

Dears, I need a script or command which can find the unique number from the second filed and against that number it adds the total of first field . 17215630 , 0 907043 ,1 201050 ,10 394149 ,4 1964 ,9 17215630, 0 907043 ,1 201050, 10 394149 ,4 1964 ,9 1234234, 55 23 ,100 33 ,67 ... (2 Replies)
Discussion started by: shary
2 Replies

8. Shell Programming and Scripting

Adding new field

Hello, I have a main file with IP addresses like this: Erisim var,100,172.17.241.5,4006,60,IS0799,TCP/IP Erisim var,1003,172.17.140.4,4004,60,IS2156,TCP/IP Erisim var,1004,172.17.140.5,4002,60,IS2636,TCP/IP Erisim var,1005,172.17.140.5,4004,60,IS2436,TCP/IP Erisim... (8 Replies)
Discussion started by: Spunkerspawn
8 Replies

9. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

10. UNIX for Dummies Questions & Answers

Adding a new field using sed or awk?

I have a bcp file that contains 10 fields. These fields are separated by a tab. How can I add my name as a new field in the 8th position for every record? I've been playing w/ sed and awk but can't seem to figure this out. (3 Replies)
Discussion started by: sasabune
3 Replies
Login or Register to Ask a Question