newbie
newbie

Reputation: 391

shell program to modify contents of a file

I have a file that has a list of product ids each on one line. I want to modify this file in a way that all product ids are on one line and comma separated and in inverted commas. Original format -

1\n2\n3\n

Expected format -

'1','2','3'

I tried the following command -

paste -s -d "','" velocities.txt > out.txt

The result is looking like this -

1',2'3'4,

I do understand that using the above command I wont get the anything before the first product id, but i will be able to handle that case.

Upvotes: 0

Views: 35

Answers (1)

Slava Semushin
Slava Semushin

Reputation: 15214

You could use sed to quote all digits:

paste -s -d, velocities.txt | sed "s|\([0-9]\+\)|'\1'|g" > out.txt

P.S. Another command that also handles IP-addressed:

sed "s|^\(.*\)$|'\1'|g" velocities.txt | paste -s -d, - > out.txt

Upvotes: 1

Related Questions