Reputation: 301
I would like to delete the second line of a text file. Using vim
or ex
any kind of text editor form script.
I have came up with these commands but does not work for me.
#!/bin/sh
iconv -f Utf-16le -t utf-8 ~/Desktop/upload.csv -o ~/Desktop/finalutf.csv
vim ':2d|wq' ~/Desktop/finalutf.csv
ex -sc '%s/\r//e|x' ~/Desktop/finalutf.csv
The script .sh
is executable. First line of code works, 3rd as well but not the second one. I tried to see the documentation for the vim commands to delete the specific line, and tried it on terminal and it works (:2d
)
trying to use it in script seems confusing. I am new to Ubuntu as well as vim and scripts, trying to learn seems hard enough, with so much of complex commands explained leaving far away, for beginners learning vim, in its documentation.
Upvotes: 1
Views: 393
Reputation: 40927
This is the sort of thing that sed
is built for.
sed -i 2d ~/Desktop/finalutf.csv
However, if you must use vim you can do
vim -c "2d|wq" ~/Desktop/finalutf.csv
Upvotes: 6