Pete
Pete

Reputation: 4622

Linux Sed adding new lines during substitution

I've got a long CSV file, I'm trying to add a double quote to the end of each line so that all values are wrapped in "

If my file looks like this:

"value", "value2", "value3
"value", "value2", "value3
"value", "value2", "value3

I'm using this command:

sed -i 's/$/"/g' file.sql

and afterwards the file looks like this:

"value", "value2", "value3
"
"value", "value2", "value3
"
"value", "value2", "value3
"

Where is that new line coming from and how do I stop it from happening?

Upvotes: 0

Views: 215

Answers (1)

Pete
Pete

Reputation: 4622

I'm a fool. The CSV I'm using to build this SQL file has come from Excel.

I need to run dos2unix to fix the new line commands. Then it is working perfectly.

Thanks to Thor for verifying the command itself is fine.

Upvotes: 1

Related Questions