The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Displaying output from df -k in GB instead of KB LinuxRacr Shell Programming and Scripting 6 09-19-2007 01:31 PM
displaying 3 directory listings in 3 separate columns. mjays Shell Programming and Scripting 16 04-04-2007 03:01 AM
displaying range of columns mahabunta Shell Programming and Scripting 1 01-26-2007 02:59 AM
displaying output in a table. sanchopansa Shell Programming and Scripting 6 10-06-2006 09:22 AM
Displaying Script command with output JeDi Shell Programming and Scripting 5 04-30-2004 08:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-25-2008
Registered User
 

Join Date: Dec 2007
Posts: 15
Displaying Output in Columns

I'm writing a script to analyze the logs of an smtp relay machine and I'd like the final output to be displayed in columns showing results from the previous day, week, month, and 45 days. The problem I'm running into is that I can't figure out how to display the columns neatly so there is no staggering.

This is similar to what I end up with:
_______________________________________________

Daily Weekly Monthy
_______________________________________________

1). 234 domain 1). 435 domain 1). 4576 domain
2). 12 domain 2). 23 domain 2). 34 domain
3). 2 domian 3). 3 domain 3). domain

Even when I use tabs between the parameters, not all the columns line up nicely.

Anyway, here's how I got this far:

After getting all the lines from the logs, I got the domain name from each line, sorted the names, counted the duplicate lines, and put the top results from each given time period into a file with the lines numbered. The file looks something like this:

1). DailyResults 346 domainName
2). DailyResults 243 domainName
3). DailyResults 123 domainName
1). WeeklyResults 345 domainName
2). WeeklyResults 234 domainName
3). WeeklyResults 123 domainName
1). MonthlyResults 345 domainName
2). MonthlyResults 234 domainName
3). MonthlyResults 123 domainName
1). TotalResults 345 domainName
2). TotalResults 234 domainName
3). TotalResults 123 domainName

Then I used a command for each line to join the lines:

echo `cat list_of_domains|grep "1)."|awk '{print $1, $2 ,$4" "$5 ,$6, $8," "$9, $10, $12" "$13, $14, $16}'`

Which gives me this output:

1). 234 domain 1). 435 domain 1). 4576 domain
2). 12 domain 2). 23 domain 2). 34 domain
3). 2 domian 3). 3 domain 3). domain

(something like this trivial example would probably line up well by using tabs between the parameters, but of course, the domain names i'm working with vary in length much more)

At this point the script is pretty ugly and I'm willing to attack this problem from a different angle if anyone has any suggestions. Any help is greatly appreciated.
THANKS!
-JJ
Reply With Quote
Forum Sponsor
  #2  
Old 04-25-2008
Registered User
 

Join Date: Mar 2008
Posts: 35
man printf

It'll allow you to block, pad, type or otherwise tweak your vars into a reasonable format.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0