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"
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!
By awk:
awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' infile
1 Like
Thanks for your quick answer but that didn't work...
Sorry this is in French ... but apparently, it didn't like /{app=$3}/
The translation is not really difficult... Context error
cgkmal
April 5, 2011, 3:24am
4
Hi Castelior,
If you need in sed, this it seems to work:
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:
awk '/Application/{A=$3};/INCIDENT/{print A}' inputfile
Hope it helps.
Regards
kurumi
April 5, 2011, 3:51am
5
Ruby(1.9+)
$ ruby -ane 'a=$F[2] if /^Application/; puts a if /INCIDENT/' file
SPVP0005
ctsgnb
April 5, 2011, 4:00am
6
sed -n '/^App/h;/INCIDENT/{g;s/.* \([^ ]*\)/\1/;p;}' infile
awk '/^App/{x=$NF}/INCIDENT/{print x}' infile
# sed -n '/^App/h;/INCIDENT/{g;s/.* \([^ ]*\)/\1/;p;}' tst
SPVP0005
# awk '/^App/{x=$NF}/INCIDENT/{print x}' tst
SPVP0005
1 Like
ni2
April 5, 2011, 4:01am
7
castelior:
Thanks for your quick answer but that didn't work...
Sorry this is in French ... but apparently, it didn't like /{app=$3}/
The translation is not really difficult... Context error
Strange it worked for me.
$awk '/Application : /{app=$3}/=== INCIDENT ==== / {print app}' file5
SPVP0005
P.S. file5 has a copy of the data you posted.
1 Like