Replace a character in last line

Hello Sed Experts,

I have got a file which contain entries as below
pmNoOfSwDownHsCong,
pmUlUpswitchAttemptHigh,
pmUlUpswitchAttemptLow,
pmUlUpswitchSuccessHigh,
pmUlUpswitchSuccessLow,
pmUpswitchFachHsAttempt,
pmUpswitchFachHsSuccess,

I want to replace the the comma "," in the last line with a space.

Can you please help me with this in sed

Thanks a lot in advance

Mohammed

try this:

sed '$s/\,//g'
sed '$s/,//g'

you don't have to escape ' , ' character

On a side note, there is no need for 'g' at the end of the 's' command.

The 'g' option replaces all instances of the string in the same line.

In this specific case, the OP says and shows that there is only one ',' (comma).

Also, the solutions remove the comma -- the OP is asking the comma to be replaced
by space:

sed '$s/,/ /' input_file

That's a cool catch ! :slight_smile:

Usually for these kind of formatting where we would be mostly interested in removing the last occurring ' , ' character ( in most of the cases if its there which doesn't add meaning )

But anyway I should have been attentive ! :slight_smile: :stuck_out_tongue:

this may mean only the last line.

Well, I am into the habit of making the replacement global. and does any one have the list of characters which has to be escaped? I suggested that because i didnt had the unix box to cross check that. Nevermind, thanks for the corrections