Register
It is currently Fri Dec 19, 2014 12:45 am

Index


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Aug 24, 2009 5:23 pm   

Joined: Thu Oct 09, 2008 3:26 am
Posts: 15
Location: Columbus, OH
Working on a ~155 line per page index. Some of the entries are like this: (/t for tab)

short/t<5 number sequence>

and

somewhat considerably longer entry on this line/t<5 number sequence>

So far I'm using
Code:
cat <filename> | grep -n -w '[0-9]\{5\}' | more -17 -p
to get command line output that doesn't clog the screen but I'd like to have the number sequences line up. printf seems to be the command to use but I can't figure out how to integrate it into the command sequence. Any help would be appreciated.

Thx,

gimp25


Top
 Profile  
 PostPosted: Mon Aug 24, 2009 5:31 pm   

Joined: Thu Oct 09, 2008 3:26 am
Posts: 15
Location: Columbus, OH
I know that I'll have to take the alpha character length as a consideration for the field size. And I forgot to tell you that the 5-digit entries could also be multiple comma separated and/or inclusive hyphenated entries.

Again, many thx.


Top
 Profile  
 PostPosted: Thu Aug 27, 2009 4:29 am   

Joined: Thu Oct 09, 2008 3:26 am
Posts: 15
Location: Columbus, OH
It took a little more reading and experimentation, but here it is......

Code:
cat filename | grep -n '[0-9]\{5\}' | awk -F"t" '{ printf ("%-41s5s\n", $1, $2) }' | more -17 -p


The printf value of 41 was selected based on the size of the longest string in the current page that I was working on +5 spaces for the line numbering provided by grep, and the spacing between the first and second fields. Also, the printf value of 5 allowed the 5-digit entries in the second field to be left aligned. Tried it with the "-", but it mangled the first field entries. I could have separated the fields by "%-41s<spaces here>5s", but it's just a matter of personal preference on this point.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP