Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

Input.txt

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

output.txt

MN556661.1   2200443     A
MN556645.1   2594155     A
MN555666.1   2594175     A
share|improve this question

3 Answers 3

up vote 2 down vote accepted
cat input.txt | awk -F\| '{print $4      $5    $6}' >> output.txt
share|improve this answer
2  
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
3  
@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

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

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

Your Answer

 
discard

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.