help needed with SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help needed with SED
# 1  
Old 04-05-2011
help needed with SED

Hello!

I have a "problem" with sed... In a log, I'm wondering how to have the name of the application when "INCIDENT" is in the file...
The name of the application is before "INCIDENT".
For this example, The result should be "SPVP0005"

Quote:
autoficsrv.sh :args=[system/manager -99 . 6900 95 2455656 56738 U019H SPVP0005 xxx U019H]
___list_batch_fics :args=[/xxx/gfprod/progs/sys/varetc/tmp/resAcsGFPROD_99.sql . 6900 95 2455656 56738 U019H SPV
P0005 xxx U019H]
-------------------------------------------------------------------------------
------ Pilote No : @(#) 5.02.05
-------------------------------------------------------------------------------
Application : SPVP0007
Date de demande : 04/04/2011
Numero d'ordre : 95
Demandeur : U810PAT3/U810PAT3 ( U810PAT3 )
Type de traitement : 2
Fichier d'edition : /xxx/gfprod/progs/sys/lis/spvp00076901
Imprimante physique : gf810_12
Imprimante logique : gf810_12i
Type fond de page : NULL
Nombre d'exemplaires : 1
Debut de traitement : Mon Apr 4 15:49:19 2011

-------------------------------------------------------------------------------
------ Fichier de messages : (varetc/log) spvp00076901.log ------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
fin de traitement == END ========== : Mon Apr 4 15:49:20 2011

autoficsrv.sh :args=[system/manager -99 . 6901 95 2455656 56957 U810PAT3 SPVP0007 XXX U810PAT3]
___list_batch_fics :args=[/xxx/gfprod/progs/sys/varetc/tmp/resAcsGFPROD_99.sql . 6901 95 2455656 56957 U810PAT3
SPVP0007 xxx U810PAT3]
-------------------------------------------------------------------------------
------ Pilote No : @(#) 5.02.05
-------------------------------------------------------------------------------
Application : SPVP0005
Date de demande : 04/04/2011
Numero d'ordre : 95
Demandeur : U700B/U700B ( U700B )
Type de traitement : 2
Fichier d'edition : /xxx/gfprod/progs/sys/lis/spvp00056902
Imprimante physique : gf700_1
Imprimante logique : gf700_1i
Type fond de page : NULL
Imprimante logique : gf700_1i
Type fond de page : NULL
Nombre d'exemplaires : 1
Debut de traitement : Mon Apr 4 15:51:20 2011

-------------------------------------------------------------------------------
------ Fichier de messages : (varetc/log) spvp00056902.log ------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
fin de traitement === INCIDENT ==== : Mon Apr 4 15:51:20 2011

autoficsrv.sh :args=[system/manager -99 . 6902 95 2455656 57074 U700B SPVP0005 xxx U700B]
___list_batch_fics :args=[/xxx/gfprod/progs/sys/varetc/tmp/resAcsGFPROD_99.sql . 6902 95 2455656 57074 U700B SPV
P0005 xxx U700B]
-------------------------------------------------------------------------------
------ Pilote No : @(#) 5.02.05
-------------------------------------------------------------------------------
Application : SPVP0004
Date de demande : 04/04/2011
Numero d'ordre : 95
Demandeur : U810BUI/U810BUI ( U810BUI )
Type de traitement : 2
Fichier d'edition : /xxx/gfprod/progs/sys/lis/budinv/spvp00046903
Imprimante physique : gf810_3
Imprimante logique : gf810_3i
Type fond de page : NULL
Nombre d'exemplaires : 1
Debut de traitement : Mon Apr 4 16:01:21 2011

-------------------------------------------------------------------------------
------ Fichier de messages : (varetc/log) spvp00046903.log ------
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
fin de traitement == END ========== : Mon Apr 4 16:02:03 2011
thanks for your help!
# 2  
Old 04-05-2011
By awk:
Code:
awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' infile

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 04-05-2011
Quote:
Originally Posted by rdcwayx
By awk:
Code:
awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' infile

Thanks for your quick answer but that didn't work...

Quote:
awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' infile>
Erreur de syntaxeLa ligne source est 1.
Le contexte de l'erreur est
/Application : >>> /{app=$3}/= <<<
awk : 0602-500 QuitterLa ligne source est 1.
Sorry this is in French Smilie ... but apparently, it didn't like /{app=$3}/
The translation is not really difficult... Context error
# 4  
Old 04-05-2011
Hi Castelior,

If you need in sed, this it seems to work:

Code:
sed -e '/Application/b;/INCIDENT/b' -e d inputfile |  sed -n 's/Application : //;/INCIDENT/{g;1!p;};h'


Maybe some sed expert could say us how to join both sed commands.

Or another option with awk:
Code:
awk '/Application/{A=$3};/INCIDENT/{print A}' inputfile



Hope it helps.

Regards

Last edited by cgkmal; 04-05-2011 at 04:42 AM..
# 5  
Old 04-05-2011
Ruby(1.9+)
Code:
$ ruby -ane 'a=$F[2] if /^Application/; puts a if /INCIDENT/' file
SPVP0005

# 6  
Old 04-05-2011
Code:
sed -n '/^App/h;/INCIDENT/{g;s/.* \([^ ]*\)/\1/;p;}' infile

Code:
awk '/^App/{x=$NF}/INCIDENT/{print x}' infile

Code:
# sed -n '/^App/h;/INCIDENT/{g;s/.* \([^ ]*\)/\1/;p;}' tst
SPVP0005
# awk '/^App/{x=$NF}/INCIDENT/{print x}' tst
SPVP0005


Last edited by ctsgnb; 04-05-2011 at 05:07 AM..
This User Gave Thanks to ctsgnb For This Post:
# 7  
Old 04-05-2011
Quote:
Originally Posted by Castelior
Thanks for your quick answer but that didn't work...



Sorry this is in French Smilie ... but apparently, it didn't like /{app=$3}/
The translation is not really difficult... Context error
Strange it worked for me.
Code:
$awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' file5
SPVP0005

P.S. file5 has a copy of the data you posted.
This User Gave Thanks to ni2 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed Help Needed

I want to search texts between first occurence of the matching pattern and replace it with some other text.pls advice what can be done. I searched alot, i could not find anything relevant. Ex my input is as follows: red yellow grey white blue red pink violet white I want to search... (9 Replies)
Discussion started by: sangitajc
9 Replies

2. Shell Programming and Scripting

some sed help needed

I have file with following contents; 127.0.0.1 www.google.com 127.3.3.1 www.cisco.com 127.3.5.1 www.msnbc.com I want output as 127.0.0.1 www.google.com google.com 127.3.3.1 www.cisco.com cisco.com 127.3.5.1 www.msnbc.com msnbc.com I tried sed 's/www.//g'... (5 Replies)
Discussion started by: sangfroid
5 Replies

3. Shell Programming and Scripting

Help needed on SED

Hi, I would like to process one file which looks like this : 09-04-16-17:11:53 -> count 1 NAME CHAN QID NMSGS NBYTES MAXBYTES P/T W_DEALNUM 105 123508770 1 10 14 P W_APPSTAT 106 123508771 1 12 35 P... (8 Replies)
Discussion started by: vive123
8 Replies

4. Shell Programming and Scripting

Help Needed in SED

Hi All , I have a input file which has set of lines like this :: cat a.txt unix1 djkdfkjdkkdfkdjfdfkjd 09191091 unix@unix.com <2008-23-07> unix 2 dfdfdfdfdfdfdfdfdfd unix3 dfldfljdflkjdfldfkljdfldjfl 0565606 unix1@unix.com <2008-10-09> unix4 dfdlfndfldflnlffddfd for some... (4 Replies)
Discussion started by: raghav1982
4 Replies

5. UNIX for Dummies Questions & Answers

SED Help Needed

I am trying to retrieve part of a line from /boot/grub/menu.lst The line is : gfxmenu (hd0,0)/usr/share/gfxboot/themes/pclinuxblue/boot/message I have figured out how to get this line into a file by itself. sed '/gfxmenu/ !d' /boot/grub/menu.lst > /tmp/menu.lst.pcl_tc What I need to... (2 Replies)
Discussion started by: Tide
2 Replies

6. Shell Programming and Scripting

Sed help needed

Hi, I have the following texts : #1#http://www.google.com#2#Google#3# #1#http://www.aol.com#2#AOL#3# I need a bash script which extracts the text between the markers (marks are #1#,#2#,#3#). I also need that text in variables ($URL and $DESCRIPT will be fine) so I can later use it to... (3 Replies)
Discussion started by: tcp27br
3 Replies

7. Shell Programming and Scripting

help with sed needed

Hi, I have a file in a form of jkkhjjk1:!:jkhdjkhjkh2:!:kljkljkljklj3:!:kljsdj4 kljlkfljf5:!:kjljljlj6:!:jhjkhjkh7 I am trying to use sed command such that everytime it find ":!:" it will removes it and print remaining of the line on the new line Output that I need will look like following... (8 Replies)
Discussion started by: arushunter
8 Replies

8. Shell Programming and Scripting

Help Needed -sed

Hi All, i have one file and in that i have to read each line and do some replacement. its is not fixed the number or column always be same it can be less also exm a;b;c;d;e;f (line) i have to do something like In the line If c is present then go to end of line and append ';date' else... (9 Replies)
Discussion started by: ravi.sadani19
9 Replies

9. Shell Programming and Scripting

Sed help needed

Could someone tell me how to replace varibles using SED inside Korn Shell? e.g. I have a ksh file program.ksh below: ------------------------------------ #!/bin/ksh sed -n '/ABC/p' $1 > output.txt if ] then status=new elif ] then status=old fi sed -n '/$status/p' $1... (5 Replies)
Discussion started by: stevefox
5 Replies

10. UNIX for Dummies Questions & Answers

Help needed with sed

Hi, I need to insert a line into a file underneath an existing line in the file, but am unsure as to the syntax. I'm pretty sure sed can be used though, although any ideas are more than welcome. For example: File ---- Line 1 Line 2 Line 3 Line 4 Line 6 I need to say: Insert "Line 5"... (1 Reply)
Discussion started by: danhodges99
1 Replies
Login or Register to Ask a Question