Reputation: 173
I want sed command which will add comma to only last line e.g i have text file which contains
"872709"
"872700"
"145"
"872808B"
"8729029921"
"879B"
"87290"
"AirHo9"
"Ait22"
"DVDSept22"
"Gr929"
want to add comma at last line
"872709"
"872700"
"145"
"872808B"
"8729029921"
"879B"
"87290"
"AirHo9"
"Ait22"
"DVDSept22"
"Gr929",
Upvotes: 2
Views: 7124
Reputation: 26667
sed -r '$ s/([a-zA-Z0-9"]*)/\1,/' inputfile
The $
mathces the last line in the file
([a-zA-Z0-9"]*
matches charactes numbers or " and the matched patter is saved in \1
back reference.
\1,
is the mathced pattern + commaa wich is the substituion pattern
test
"872709"
"872700"
"145"
"872808B"
"8729029921"
"879B"
"87290"
"AirHo9"
"Ait22"
"DVDSept22"
"Gr929",
Upvotes: 1
Reputation: 785058
You can use sed
:
sed '$s/$/,/' file
"872709"
"872700"
"145"
"872808B"
"8729029921"
"879B"
"87290"
"AirHo9"
"Ait22"
"DVDSept22"
"Gr929",
To make it save changes inline use:
sed -i.bak '$s/$/,/' file
Upvotes: 11