シェルコマンドを使用して一致する各文字列の後に新しいテキストを追加するには?

シェルコマンドを使用して一致する各文字列の後に新しいテキストを追加するには?

入力する:

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

出力:

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

Changes has been updated to all servers文字列に一致するすべての行にこのテキストを追加し、文字列に一致する行のODB_ACTIAVTION SUCCESSFULNo changeにテキストを追加したいと思いますODB_ACTIAVTION UNSUCCESSFUL

答え1

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

答え2

そして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

そしてsed

sed -e '
  /ODB_ACTIAVTION SUCCESSFUL/a\
  Changes has been updated to all servers
  /ODB_ACTIAVTION UNSUCCESSFUL/a\
  No change
' <in >out

関連情報