LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-18-2009, 04:33 AM   #1
khaos83
Member
 
Registered: Dec 2007
Posts: 97

Rep: Reputation: 15
Question Help to do up a well formatted report?


File 1
Code:
Name Number1
Peter 123
John 3
ALONGNAME 5432
File 2
Code:
Name Number2
Peter 987
John 72
ALONGNAME 1
I am trying to combine the 2 reports into a well formatted report. But the irregular letter count is my biggest problem.
I join and awk to put tabs in between but the format is off.

e.g.
Combined report
Code:
Name   Number1    Number2
Peter  123    987
John   3      72
ALONGNAME    5432     1

I wish it to be like this
Combined report
Code:
Name      Number1    Number2
Peter     123        987
John      3          72
ALONGNAME 5432       1

Is there anyway to overcome this?
I can handle how file 1 and 2 is formatted, if that helps in my quest.
 
Old 05-18-2009, 05:14 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Have a look at awk's printf, specifically the %xx[sd...] semantics,
where xx defines the width of your field (you could also right-justify
your numbers - which is more common).
Code:
awk '{if( $3 ~ /[a-zA-Z]/ ){printf "%-10s%10s%10s\n", $1,$2,$3}else{printf "%-10s%10d%10d\n",$1,$2,$3}}' file

Cheers,
Tink
 
Old 05-18-2009, 09:21 PM   #3
khaos83
Member
 
Registered: Dec 2007
Posts: 97

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Tinkster View Post
Have a look at awk's printf, specifically the %xx[sd...] semantics,
where xx defines the width of your field (you could also right-justify
your numbers - which is more common).
Code:
awk '{if( $3 ~ /[a-zA-Z]/ ){printf "%-10s%10s%10s\n", $1,$2,$3}else{printf "%-10s%10d%10d\n",$1,$2,$3}}' file

Cheers,
Tink
Thanks! That works.
I also made a few changes to fit even better than before.
 
Old 05-19-2009, 12:36 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by khaos83 View Post
Thanks! That works.
I also made a few changes to fit even better than before.
Cool - glad I could hint you in the right direction! =}


Cheers,
Tink
 
  


Reply



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
Lire (log analysis, log report) no report in Mandriva 2005 LE (desktop usage) Emmanuel_uk Mandriva 0 01-16-2006 02:11 AM
how to use xp-formatted HD under suse? Gulae Linux - Newbie 4 12-22-2005 07:12 AM
Formatted output with g++ boa Programming 3 11-25-2003 09:57 AM
How can I report the Error Report? domeili Linux - Newbie 1 10-30-2003 05:42 AM
what if i formatted it vfat ? RHlinux9 Linux - Newbie 4 09-15-2003 11:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:40 PM.

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
Open Source Consulting | Domain Registration