I have a file "test"
Below is the content
235788@@@235788@@@20200724_103122@@@SUCCESS
235791@@@235791@@@20200724_105934@@@SUCCESS
235833@@@235833@@@20200724_130652@@@FAILURE
235842@@@235842@@@20200724_132721@@@FAILURE
235852@@@235852@@@20200724_134607@@@FAILURE
235791@@@235791@@@20200724_105934@@@SUCCESS
if last line of this file begin with 235791 then replace string "SUCCESS" to "FAILURE" on just that line.
Expected Output
235788@@@235788@@@20200724_103122@@@SUCCESS
235791@@@235791@@@20200724_105934@@@SUCCESS
235833@@@235833@@@20200724_130652@@@FAILURE
235842@@@235842@@@20200724_132721@@@FAILURE
235852@@@235852@@@20200724_134607@@@FAILURE
235791@@@235791@@@20200724_105934@@@FAILURE
Below is the sample code
id = 235791
last_build_id = `tail -1 test | awk -F'@@@' '{print \$1}'`
if (id == last_build_id ){
sed -i '$s/SUCCESS/FAILURE/' test
}
I would like to avoid these many lines and use one line shell command using regex groups or in any other simple way.