HELP : awk substr

Hi,

  • In a file test.wmi
Col1 | firstName | lastName
4003 | toto_titi_CT- | otot_itit
  • I want to have only ( colones $7,$13 and $15) with code 4003 and 4002 . for colone $13 I want to have the whole name untill _CT- or _GC-

1- I used the command egrep with awk

#egrep -i "EventID=4002|EventID=4003" test.wmi |awk -F '[=|<|>]' '{print $7, substr($13,1,38),$15 }' 

file out:

4003   GTWPRD_FT_Assurnet_controle_flux_CT-As         st_assurnet_controleMSG_decompte_rejet_AMO:
4003   SAVKHE_SV_SAVJ_GC_ALICIA_RH_SAUVEGARDE    lance_tina:
4003   ASSNET_ST_CYCLIQUE                                     expl_st_pilot_export:
4003   ASSNET_ST_CYCLIQUE                                     expl_st_cftenv:
4003   GTWPRD_FT_Assurnet_controle_flux                    CT-Assurnet_controle_flux:
4003   GTWPRD_FT_Assurnet_controle_flux_CT-As          Put_Fichier_Decompte_AMC:
4003   GTWPRD_FT_Assurnet_controle_flux_CT-As          Put_Fichier_Assure_AMC:

2- I used sed to avoid the : in the end of 3rd colone

[tmp]# egrep -i "EventID=4002|EventID=4003" test.wmi |awk -F '[=|<|>]' '{print $7, substr($13,1,38),$15 }' | sed 's/:[ \t]*//'

file out-

4003  GTWPRD_FT_Assurnet_controle_flux_CT-As           st_assurnet_controleMSG_decompte_rejet_AMO
4003  SAVKHE_SV_SAVJ_GC_ALICIA_RH_SAUVEGARDE      lance_tina
4003  ASSNET_ST_CYCLIQUE                                       expl_st_pilot_export
4003  ASSNET_ST_CYCLIQUE                                       expl_st_cftenv
4003  GTWPRD_FT_Assurnet_controle_flux                      CT-Assurnet_controle_flux
4003  GTWPRD_FT_Assurnet_controle_flux_CT-As             Put_Fichier_Decompte_AMC
4003  GTWPRD_FT_Assurnet_controle_flux_CT-As             Put_Fichier_Assure_AMC
  • in the case i Have a name with _CT-"GTWPRD_FT_Assurnet_controle_flux_CT-As" i want only have the name before _CT- " GTWPRD_FT_Assurnet_controle_flux"
    Can someone help me to find the command to do this
    thks
    georg

I am completely lost.

You show us an input file containing 2 lines.

You show us an egrep that selects lines from that file containing the case insensitive string EventID and you magically produce seven lines of output when that string does not appear anywhere in your sample input file.

You show us a sample input file that contains two pipe symbols ( | ) and an awk script that uses the characters = , | , < , and > as field separators and prints all or parts of fields 7, 13, and 15 when your input file only contains three fields.

I do not understand where any of the data you showed us as sample output came from???

1 Like

Wrong subforum... Please watch out where to post your problems!

1 Like