Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Input:

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

Output:

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

I want to add these text Changes has been updated to all servers in every line matched with the string ODB_ACTIAVTION SUCCESSFUL and No change text after the line matched with the string ODB_ACTIAVTION UNSUCCESSFUL.

share|improve this question
    
Yes but there is some differences... the text what will be added is different and based on two different texts also @don_crissti –  pmaipmui Aug 18 at 17:34
    
not only the word ACTIVATION ... there is two different text ..ODB_ACTIAVTION SUCCESSFUL and ODB_ACTIAVTION UNSUCCESSFUL @don_crissti –  pmaipmui Aug 18 at 18:27

2 Answers 2

up vote 1 down vote accepted

With 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

With sed:

sed -e '
  /ODB_ACTIAVTION SUCCESSFUL/a\
  Changes has been updated to all servers
  /ODB_ACTIAVTION UNSUCCESSFUL/a\
  No change
' <in >out
share|improve this answer
    
$0 is for new blank line? @cuonglm –  pmaipmui Aug 18 at 17:30
    
Yes.... both the answers are working... :-) @cuonglm –  pmaipmui Aug 18 at 17:32
    
@Nainita: No, $0 is data for %s format in printf. –  cuonglm Aug 18 at 17:33
    
yes... I have already checked... @cuonglm –  pmaipmui Aug 18 at 17:35
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
share|improve this answer
    
yes... it's working perfectly @unxnut –  pmaipmui Aug 18 at 18:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.