file.txt:
if (early_timeout == TRUE) {
sprintf(send_buff, "XYZ: Command timed out",
command_timeout);
result = UNKNOWN;
}
Above is the sample content of file with proper indentation. Having a bit difficulty when trying to replace XYZ
with ABC
using sed
,
- When using
sed -i '/^.*sprintf/ s/XYZ/ABC/g' file.txt
But this results in taking (printf, asprintf) as comparing word and replacing every occurance of line starting with (sprintf,asprintf, etc) throught the file, though I just need to replace line containingsprintf
. - When used
sed -i '/^.sprintf/ s/XYZ/ABC/g' file.txt
to compare the first word of line in this case i.esprintf
to compare and replace, but it is failing in case of extra indentation in the file.
Is there any way to particularly compare for word starting in line anywhere and then sed to replace.
One way I come across is, to align contents of my file.txt to left side on std output using sed -r 's/^[ \t]*//'
and then apply sed -i '/^.sprintf/ s/XYZ/ABC/g' file.txt
, Is there any way to combine and run in one go or any other way to achieve this? This seems to be not working as well and I'm a bit lost.