Angelo
Angelo

Reputation: 5059

Transforming an n-column file to a single-column file

I have a file like this

chr1:752426-753176_NR_015368_LOC643837 chr1:752515-753265_NR_024321_NCRNA00115 

Where separation is with a tab, it has n number of columns and n number of rows.

What I want to do is to have one single column of my whole data. like this

chr1:752426-753176_NR_015368_LOC643837 
chr1:752515-753265_NR_024321_NCRNA00115 

Is there any one-liner in shell or Perl that can help me achieve this?

Thank you in advance.

Upvotes: 1

Views: 54

Answers (2)

Zaid
Zaid

Reputation: 37136

Yes, it is possible.

  • Use the -a flag to split @F on columns
  • print or say each element of @F
  • Use > to redirect output to a new file or use the -i flag to enable in-place editing.

    $ perl -anE 'say for @F' input.txt > output.txt
    

Upvotes: 1

codaddict
codaddict

Reputation: 454950

You can try doing:

sed -i.bak 's/\t/\n/g' file

Upvotes: 2

Related Questions