LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2014, 09:05 AM   #1
sonia102d
LQ Newbie
 
Registered: Sep 2012
Posts: 18

Rep: Reputation: Disabled
Unhappy 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 ?
 
Old 03-13-2014, 09:33 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
Code:
perl -nle 'print join "\t", split(/\s+/, $_)'  < infile > outfile
 
1 members found this post helpful.
Old 03-13-2014, 09:44 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
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
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory alignment C code issue when using O_DIRECT flag to open a file surajchalukya Programming 4 07-27-2012 08:34 AM
Data alignment, mantu55 Linux - Software 2 05-25-2012 05:21 AM
[SOLVED] Alignment of a file vikas027 Programming 4 04-23-2009 07:36 AM
about alignment eshwar_ind Programming 5 10-18-2004 09:27 AM
glabels alignment Spaz17 Linux - Software 1 11-28-2003 02:17 PM


All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration