LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Alignment question in file (https://www.linuxquestions.org/questions/linux-newbie-8/alignment-question-in-file-4175498039/)

sonia102d 03-13-2014 08:05 AM

Alignment question in file
 
How to align and indent a file?


Hi

I can indent a code in eclipse but I have a doubt for huge file which needs to be indented and aligned.The words in each line have to be specifically separated by tabs.

The ideal line is like one below.
All the words are seperated by tab except the last set of words ie name,id,sourceid group.

Code:

POINT  era    parent  206  498  0.974692        +      .      Name=pq2.1;ID=pq2;source_id=l_Le10020385;identical_details=.;part_details=.;TWIN=pq121749.1;

my file
Code:

POINT  era    parent  206  498  0.974692        +      .      Name=pq2.1;ID=pq2;source_id=l_Le10020385;identical_details=.;part_details=.;TWIN=pq121749.1;
POINT  era    minor  206  228  0.974692        +      .      Name=pq2.1;ID=pq2.1;source_id=l_Le10020385;identical_details=.;part_details=.;TWIN=pq121749.1;
POINT  era    cluster 206  2928  .      +      0      source=pq2.1;
POINT era parent 382 347 0.955489 + . Name=pq3.1;ID=pq3;source_id=l_Le10020387;identical_details=.;part_details=QWE4.1805.1,QWE4.1805.1;TWIN=pq121751.1;
POINT  era    minor  379  347  0.955489        +      .      Name=pq3.1;ID=pq3.1;source_id=l_Le10020387;identical_details=.;part_details=QWE4.1805.1,QWE4.1805.1;TWIN=pq121751.1;
POINT  era    clust_5 382  878  .      .      .      source=pq3.1;details=QWE4.1805.1;
POINT  era    cluster 326  347  .      +      0      source=pq3.1;
POINT era parent 408716 416853 0.999853 - . Name=pq4.1;ID=pq4;source_id=l_Le10020388;identical_details=QWE4.1812.2;part_details=.;

After manual inspection ,the lines which have parent in 3rd tab mostly have this misalignment.Others are all proper.
Is there a way I could have them aligned like in order i previously put ?

linosaurusroot 03-13-2014 08:33 AM

Code:

perl -nle 'print join "\t", split(/\s+/, $_)'  < infile > outfile

pan64 03-13-2014 08:44 AM

would be faster to replace \s+ with \t, but I'm not really sure it will solve all that alignment problems.
sed -r 's/\s+/\t/g' infile > outfile


All times are GMT -5. The time now is 03:01 AM.