Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have a text file.

number 1_1 \t number1_2 \t etc
number 2_1 \t number2_2 \t etc

I want to remove the first column of this file (corresponding to number1_1, number2_1 etc, ie the numbers before the first tab for each row). I read this post that proposes a solution to delete the first column (see Peter's answer). However, it doesn't work for me as the numbers have different sizes and I cannot repeat the operation to delete the first column. How can I do then?

share|improve this question
Do you want a vim specific solution? – i08in May 26 '14 at 9:48
preferably, but not necessarily (what else do you propose?) – bigTree May 26 '14 at 9:48
@bigTree do you want command line answers? – Avinash Raj May 26 '14 at 10:00
@AvinashRaj Command line answers would be good thanks – bigTree May 26 '14 at 10:04

4 Answers 4

up vote 4 down vote accepted

This should delete all chars before and including the 1st tab on any line:


Command line cut:

cut -f 2- {filename.txt} > {filenamenew.txt}

cut defaults to tabs; if you want something else like a space add -d " ". -f is fields to copy over. 2- means all from (and including) column 2.

share|improve this answer

Through awk,

awk -F"\t" '{print FS,$2}' file > newfile

It cuts the first column and prints only the remaining tab and second column.

Through sed,

sed -r 's/^([^\t]*)\t(.*)$/\t\2/g' file > newfile
share|improve this answer


On every line (%), replace (<code>/<em>ORIGINAL</em>/<em>REPLACEMENT</em>/</code>) the first occurrence of “non-tab characters ([^\t]) in any numbre (*) followed by a tab\t” by nothing. You can type <kbd>Tab</kbd> instead of\t`.

Alternatively you can match the shortest sequence of characters (.\{-}) ending in a tab. .*\t would match the longest match for .*, so it would match all but the last column; .\{-} matches the shortest match which is the first column.


share|improve this answer

In Vi to remove first column (separated by space), you can do:

:%norm dW

for a column separated by Tab, it's:

:%norm dfCtrl+VTab

So the command which would remove the first column from file (in-place) can be:

ex +"%norm df$(echo -e '\t')" -scwq file

To check the output before saving (dry-run), replace -scwq with -sc'%p|q!'.

Or based on Chris suggestion, like:

ex -c':exe ":%norm df\<Tab>"' -sc'%p|q!' <(echo -e "a a\tb b\tc c")

Alternatively do it in visual mode (if starting from the top-left):

  1. Enter visual-block by Ctrl+v.
  2. Jump at the end and select first column by pressing: G, E (or adjust manually).
  3. Press d to delete the selected block.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.