1

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.

2 Answers 2

6

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
Sign up to request clarification or add additional context in comments.

Comments

4

This works for me:

vim -c "2d|wq" infile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.