I have a tab-delimited file like:
name1 verb1 name2 verb2 etc...
I want to delete the second column. I tried editing one of these answers, but being not familiar with
awk, I couldn't.
Can anyone help me?
In vim, you should be able to use the command
(substitute TAB followed by zero or more occurrences of any character except TAB with nothing). If your file has only two columns you could use a slightly simpler
:%s/\t.*$which replace the first TAB and any following characters up to the end of the line.
The accepted answer is much more elegant than this (I upvoted it!) but if you do not remember it you can use
vim visual block mode directly. Open vim and go (normal mode) to the first corner of the column, like this:
CTRL-V and you can move the cursor to select the column, this is midway:
To go at the end, press
the block seems broken because we are on the last line which is blank; simply go up one line (with the up arrow or
k) to see it again...:
Now you simply press
x to delete the block:
I would use
cut for this
cut -f1,3- file.txt > newfile.txt mv newfile.txt file.txt
You can use this as a filter within vim, too (this will replace all the lines in the file; you could also use (for example)
2,9 instead of
% to process lines 2-9, or select the lines you want with
-f1,3- means 'print field one, followed by field three and all fields until the end of the row'. By default,
cut uses a tab as its delimiter; if you need something else, use the
-d option (see
You can try either:
or manually using visual mode:
To do it in-place from the command line, try:
$ ex +':exe ":%norm f\<Tab>dE"' -scx file