Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tab-demlimted text file with 50,000lines. I want to split the first column and print as shown in output.txt


rt|371443144|mb|MN556661.1|  2200443     A
rt|371443344|mb|MN556645.1|  2594155     A
rt|371467899|mb|MN555666.1|  2594175     A


MN556661.1   2200443     A
MN556645.1   2594155     A
MN555666.1   2594175     A
share|improve this question
up vote 2 down vote accepted
cat input.txt | awk -F\| '{print $4      $5    $6}' >> output.txt
share|improve this answer
I never understand why people use cat in such a situation? – Bernhard Nov 2 '12 at 19:24
My answer addressed his question using the tools he provided. Sure you can use just awk by itself, or perl to do the same thing. – Mark Cohen Nov 2 '12 at 19:39
@MarkCohen Bernhard was referring to the useless use of cat; you can achieve the same effect with awk -F\| '{...}' file.in >file.out – Kevin Dec 13 '12 at 21:37

An alternative with cut would be:

cut input.txt -d'|' -f4-5 --output-delimiter='' >> output.txt

By the way, you mentioned in the question that it is tab delimited, but I took the | here as delimiter.

share|improve this answer
This example fails on my test system :usage: cut -b list [-n] [file ...] cut -c list [file ...] cut -f list [-s] [-d delim] [file ...] – Mark Cohen Nov 2 '12 at 19:41

You could do it like this with GNU sed:

sed -r 's/([^|]+\|){3}//; s/\|//'

i.e. delete three groups preceded by pipes, the second substitute command removes pipe after the 4th field.

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.