Unix Shell Script n’obtient que les lignes nécessaires à partir d’un contenu de fichier avec certains critères sur la prochaine ligne à prendre en compte

AIDE ……. TOUJOURS PAS TRAVAILLER

Rubrique connexe

J’ai un fichier contenant des chaînes:

Logs.txt

http://mediafire.com/?a6o37kfc7m68dri

Contenu partiel:

 BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/1746056 BIF in setInputTag> set input tag value, name/value:bill_ref_no/197546058 BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 BIF in setInputTag> set input tag value, name/value:NOD_FLAG/0 BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/510312 BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/510312 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLZIPCODE) into ACCT map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLEDACCOUNTNUMBER) into ACCT map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLNUMBER) into ACCT map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLNUMBERRESETS) into ACCT map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=10593131,0 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=26203008,0 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=57292633,0 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=914416,0 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=914415,0 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(OWNINGACCOUNTNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBER) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(SUBSCRBNUMBERRESET) into SI inherited_map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(DEFAULTEXTERNALID) into SI inherited_map BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=57292561,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=914415,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=914416,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=10593131,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=26203008,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=57292561,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=57292633,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=914415,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=57292561,0 BIF in InvoiceRecord> INFO: Output data to SI map,successful. SI=57292561,0 BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/1746056 BIF in setInputTag> set input tag value, name/value:bill_ref_no/202085235 BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 BIF in setInputTag> set input tag value, name/value:NOD_FLAG/0 BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/962908 BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/962908 BIF in run> INFO: updateParameterValues finished BIF in getFile> INFO: Feed file(/arbordata/feedfile/PS-M26-1104-20130726-20130911-201711-1-bif01-1.DAT) for current invoice BIF in insertNewFile> m_pcurFileNameAttr->file_seq_no:(1) BIF in insertNewFile> INFO:Output fileHeader(000020130911201711 ) to feedfile,successful BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/1746056 BIF in setInputTag> set input tag value, name/value:bill_ref_no/202085235 BIF in setInputTag> set input tag value, name/value:bill_ref_resets/1 BIF in setInputTag> set input tag value, name/value:DISPUTE_AMOUNT/0 BIF in setInputTag> set input tag value, name/value:NOD_FLAG/1 BIF in setInputTag> set input tag value, name/value:OUTSTANDING_BALANCE/962908 BIF in setInputTag> set input tag value, name/value:TOTAL_DUE/962908 BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLZIPCODE) into ACCT map BIF in addInheritedByField> INFO: Succeed to put the inherited value of field(BILLEDACCOUNTNUMBER) into ACCT map BIF in addInheritedByField> INFO: Succeed to put the inhelibarbor_db/database_gen.c(4670): arb_db_err - Entry errtype = 2 exec_user_handler = 1 errcode = 1422 errtext = Error in execution of OCI function unused: retcode = -1 (OCI_ERROR) ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at "ARBOR.PROJ_CSA_PROC2", line 9 

Mon scénario est que je veux créer un script .sh qui obtiendra toutes les chaînes nécessaires à partir du fichier et le formatera comme ci-dessous et enfin le sortir dans un nouveau fichier:

modifier

 1729030|192840714|1|1422|Error in execution of OCI function unused: 1746056|202085235|1|1422|Error in execution of OCI function unused: 809434|201632617|1|1422|Error in execution of OCI function unused: 6993375|202888775|1|1422|Error in execution of OCI function unused: 7453294|199851665|1|1422|Error in execution of OCI function unused: 

Où:

  • Colonne1: BIF in setInputTag> set input tag value, name/value:ACCOUNT_NO/ 1729030
  • Colonne2: BIF in setInputTag> set input tag value, name/value:bill_ref_no/ 192840714
  • Colonne3: BIF in setInputTag> set input tag value, name/value:bill_ref_resets/ 1
  • Colonne4: errcode = 1422
  • Colonne5: errtext = Erreur dans l’exécution de la fonction OCI inutilisée:

MODIFIER

Enfin je me sens plus proche de mon objective

Après avoir exécuté ce code:

 egrep -e 'ACCOUNT_NO|bill_ref_no|bill_ref_resets|errcode|errtext' logs.txt | awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=4 a=0 s='errtext' 

(MÊME CI-DESSUS: Rompre en ligne) – Lorsque vous le lancez, vous le mettez dans une ligne:

 egrep -e 'ACCOUNT_NO|bill_ref_no|bill_ref_resets|errcode|errtext' logs.txt |awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=4 a=0 s='errtext' 

modifier

Après avoir ajouté cette ligne de code à mon code précédent:

 | sed -e 's/=/:/' -e 's/^BIF.*://' -e 's=/=:=' -e 's/^ *//' -e 's/ *: /:/' | sed -e 's/ACCOUNT_NO://g' -e 's/bill_ref_no:/|/g' -e 's/bill_ref_resets:/|/g' -e 's/errcode:/|/g' -e 's/errtext:/|/g' 

c’est ma sortie maintenant:

 1729030 |192840714 |1 |1422 |Error in execution of OCI function unused: 1746056 |202085235 |1 |1422 |Error in execution of OCI function unused: 809434 |201632617 |1 |1422 |Error in execution of OCI function unused: 6993375 |202888775 |1 |1422 |Error in execution of OCI function unused: 7453294 |199851665 |1 |1422 |Error in execution of OCI function unused: 

Le problème final est maintenant comment couper la nouvelle ligne pour avoir une sortie ci-dessous

il a essayé d’append ce code mais cela ne fonctionne pas:

 | sed -e 's/\n//g;' 

Comment couper ces nouvelles lignes?

La sortie souhaitée est:

 1729030|192840714|1|1422|Error in execution of OCI function unused: 1746056|202085235|1|1422|Error in execution of OCI function unused: 809434|201632617|1|1422|Error in execution of OCI function unused: 6993375|202888775|1|1422|Error in execution of OCI function unused: 7453294|199851665|1|1422|Error in execution of OCI function unused: 

MON CODE ENTIER MAINTENANT:

 egrep -e 'ACCOUNT_NO|bill_ref_no|bill_ref_resets|errcode|errtext' logs.txt | awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=4 a=0 s='errtext' | sed -e 's/=/:/' -e 's/^BIF.*://' -e 's=/=:=' -e 's/^ *//' -e 's/ *: /:/' | sed -e 's/ACCOUNT_NO://g' -e 's/bill_ref_no:/|/g' -e 's/bill_ref_resets:/|/g' -e 's/errcode:/|/g' -e 's/errtext:/|/g' | sed -e 's/\n//g;' 

S’il vous plaît essayer ceci,

 egrep -e 'ACCOUNT_NO|bill_ref_no|bill_ref_resets|errcode|(Error in execution)' logs.txt | grep -B4 'Error in execution' | sed -e 's/ACCOUNT_NO\/\(.*\)/\1|/' -e 's/.*bill_ref_no\/\(.*\)/\1|/' -e 's/.*bill_ref_resets\/\(.*\)/\1|/' -e 's/.*errcode.*= \(.*\)/\1|/' -e 's/.*errtext.*= \(.*\)/\1/' -e '/--/d' | tr -d '\n' | sed -e 's/:/:\n/g' -e 's/ |/|/g' > out_put_file.txt 

J’ai travaillé sur Ubuntu 12.10 avec bash. C’est trop long donc je le divise en plusieurs lignes, lorsque vous l’exécutez, vous devez les mettre dans une seule ligne. StackOverflow a également des problèmes de mise en forme. Je dois modifier ceci pour afficher la ligne de commande complète.

Ceci est ma sortie,

 1729030|192840714|1|1422|Error in execution of OCI function unused: 1746056|202085235|1|1422|Error in execution of OCI function unused: 809434|201632617|1|1422|Error in execution of OCI function unused: 6993375|202888775|1|1422|Error in execution of OCI function unused: 7453294|199851665|1|1422|Error in execution of OCI function unused: 

Il semble que la deuxième ligne de votre sortie d’origine ne soit pas correcte sur la base de logs.txt.

Une seule commande awk peut faire:

 #!/usr/bin/awk -f { if (/ACCOUNT_NO/) { sub(/.*\//, "") account_no = $NF step = 2 } else if (/bill_ref_no/) { if (step++ == 2) { sub(/.*\//, "") bill_ref_no = $NF } else { step = 1 } } else if (/bill_ref_resets/) { if (step++ == 3) { sub(/.*\//, "") bill_ref_resets = $NF } else { step = 1 } } else if (/errcode/) { if (step++ == 4) { sub(/.* = /, "") errcode = $0 } else { step = 1 } } else if (/errtext/) { if (step == 5) { sub(/.* = /, "") print account_no "|" bill_ref_no "|" bill_ref_resets "|" errcode "|" $0 } step = 1 } } 

Courir comme:

 awk -f script.awk log.txt 

Sortie basée sur les données ci-dessus:

 1746056|202085235|1|1422|Error in execution of OCI function unused: