Reputation: 55
I have a file with multiple lines. Something like this:
Session
PKG_TEST
Call: command(parameter);
Error: error message
end of log;
Session2
PKG_TEST2
Call: command2(parameter2);
Error: error message
end of log;
I need to remove the semicolon at the end of each line that starts with Call.
I know how to find every line that starts with Call
with /^Call.*/
, but can't make everything in one sed command without deleting every semicolon in the file. How can I do that?
Upvotes: 1
Views: 45
Reputation: 52441
To run a substitution only on lines that match a pattern, you can append the substitution to an address:
sed '/^Call/s/;$//' infile
This checks if your line matches ^Call
, and if so, it executes s/;$//
, which removes a trailing semicolon.
Upvotes: 2