Home > Net >  Write a Bash Script to edit a csv file
Write a Bash Script to edit a csv file

Time:12-15

So i have a csv file like

Sam,0.0.1
Smith,0.0.1

I want to append

Ria,0.0.1

Final result should look like this

Sam,0.0.1
Smith,0.0.1
Ria,0.0.1

the command i used:

sed -i s/\'smith,0.0.1\'/\'smith,0.0.1\',\'Ria,0.01'\'/g <name of csv>

what it does is

Sam,0.0.1
Smith,0.0.1, Ria,0.0.1

CodePudding user response:

Try to add \n before Ria.

The command should be:

sed -i s/'smith,0.0.1'/'smith,0.0.1','\nRia,0.01''/g

The \n indicates new line.

CodePudding user response:

Like this:

sed -i '$a Ria,0.0.1' file
  • $ stands for last line
  • a stands for append
  • Related