Como adicionar um novo texto após cada string correspondente usando o comando shell?

0

Entrada:

Job name: ns, Job ID: 2312, Status: ODB_ACTIAVTION SUCCESSFUL
Job name: ps, Job ID: 3353, Status: ODB_ACTIAVTION SUCCESSFUL
Job name: pm, Job ID: 1265, Status: ODB_ACTIAVTION SUCCESSFUL
Job name: np, Job ID: 7885, Status: ODB_ACTIAVTION SUCCESSFUL
Job name: as, Job ID: 3215, Status: ODB_ACTIAVTION UNSUCCESSFUL

Saída:

Job name: ns, Job ID: 2312, Status: ODB_ACTIAVTION SUCCESSFUL
Changes has been updated to all servers
Job name: ps, Job ID: 3353, Status: ODB_ACTIAVTION SUCCESSFUL
Changes has been updated to all servers
Job name: pm, Job ID: 1265, Status: ODB_ACTIAVTION SUCCESSFUL
Changes has been updated to all servers
Job name: np, Job ID: 7885, Status: ODB_ACTIAVTION SUCCESSFUL
Changes has been updated to all servers
Job name: as, Job ID: 3215, Status: ODB_ACTIAVTION UNSUCCESSFUL
No change

Eu quero adicionar esse texto Changes has been updated to all servers em cada linha correspondente à string ODB_ACTIAVTION SUCCESSFUL e No change text depois que a linha corresponder à string ODB_ACTIAVTION UNSUCCESSFUL .

    
por pmaipmui 18.08.2015 / 19:19

2 respostas

1

com awk :

awk '
/ODB_ACTIAVTION SUCCESSFUL/{printf "%s\nChanges has been updated to all servers\n", $0}
/ODB_ACTIAVTION UNSUCCESSFUL/{printf "%s\nNo change\n", $0}
' <in >out

com sed :

sed -e '
  /ODB_ACTIAVTION SUCCESSFUL/a\
  Changes has been updated to all servers
  /ODB_ACTIAVTION UNSUCCESSFUL/a\
  No change
' <in >out
    
por 18.08.2015 / 19:29
2
awk '/ODB_ACTIAVTION SUCCESSFUL/ {printf "%s\nChanges has been updated to all servers\n", $0}
     /ODB_ACTIAVTION UNSUCCESSFUL/ {printf "%s\nNo change\n", $0}' file1 > file2
    
por 18.08.2015 / 19:28