|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hello friends Please help me to display the content of a file in specific aligned manner. for ex. the content of the file may be [code] >$TEST WELCOME HI HELLO UNIX SHELL SCRIPTING >$ I want to display the content like Code:
. TEST WELCOME HI HELLO UNIX SHELL SCRIPTING .... . Here we need to consider the longest word of the file( in this ex SCRIPTING = 9),So after each word there should me some empty spaces, ex: TEST has only 4 letters in it, So I need 5 empty space following TEST so 4+5 = 9...like this i need to display the content ( Here in this site the empty spaces are not coming) Please help me to fix this..I'm trying this for since 10 days..couldn't figure it out...Thanks in advance...
Last edited by rajmohan146; 06-04-2012 at 10:23 AM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
If you had used code tags, you would have noticed it keeps spacing and indent format...
|
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Ever considered using
pr command ? (Its magic...)
|
|
#4
|
|||
|
|||
|
Thanks
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Code:
awk 'BEGIN{ORS=""} {printf("%-9s", $1)}' infile >outfile |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
But I need to print more than one word( say TEST , HI, HELLO) in a same line...
Like matrix format ---------- Post updated at 09:36 AM ---------- Previous update was at 09:24 AM ---------- Sdf Thanks for the help I need the counter to be reseted when starting of every line..I mean the output line Last edited by rajmohan146; 06-06-2012 at 02:52 AM.. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
---------- Post updated at 10:25 PM ---------- Previous update was at 04:42 PM ---------- @ rajmohan146 This script determines the longest word of the file and paddes the rest of the field with empty spaces according to the longest word of the file: Code:
awk '{a[i++]=$1; if(length($1) > length(max)) max=$1;l=length(max)} END{ for(j=1; j<=i;j++) printf("%"(l+1)"s,",a[j-1])}' infile > outfileoutput Code:
TEST, WELCOME, HI, HELLO, UNIX, SHELL, SCRIPTING, Good luck! Last edited by sdf; 06-05-2012 at 03:02 AM.. Reason: adjusted script |
| The Following User Says Thank You to sdf For This Useful Post: | ||
rajmohan146 (06-06-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Aligning columns in a text file using Perl | smarty86 | Shell Programming and Scripting | 8 | 04-20-2012 06:01 AM |
| Aligning numbers in the second file based on first file | shoaibjameel123 | Shell Programming and Scripting | 4 | 09-08-2011 12:57 AM |
| Aligning text files by max field length | physalis2099 | Shell Programming and Scripting | 7 | 08-11-2011 06:30 PM |
| Aligning for boundary conditions | axes | Programming | 3 | 07-26-2010 01:01 PM |
| Aligning Characters in Bash/Beautiful Screens | de_la_espada | UNIX for Dummies Questions & Answers | 1 | 08-02-2009 07:46 AM |
|
|