Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-27-2014, 11:30 AM   #1
LQ Newbie
Registered: Feb 2014
Posts: 8

Rep: Reputation: Disabled
Trying to use awk to generate a report

Alright, here's the deal:

I currently have a script that checks whether some cameras have been recording continuously since a given date. If it finds times where the recording stopped it echos the path and how much time was stored there. This all works fine so I don't need any help there.

Now I want to create a script that takes everything printed by the last script and organizes it into a nice table. Would awk be the best thing to use for this?

I can still manipulate what the output of the other script is so I figure I should be able to put some sort of separator in (";" maybe). The table will have to show a few different types of errors (not enough time, camera reset, etc.) along with the path so I might need different types of separators for different things? This is my first time writing a script of this nature so I'm just throwing some ideas out there.

If anyone could give me some insight as to how to get started that would make this much easier. I don't want to sink a few hours into this just to find out I could have used a much easier method.

Thanks in advance!
Old 02-27-2014, 11:38 AM   #2
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Awk could do it, but it may not be the best solution

You can probably get your existing script to output the desired format,
For example instead of using echo use printf

if you still need help, show us your script(s), input data and desired output
Old 02-27-2014, 11:56 AM   #3
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 & 7
Posts: 3,271

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
awk is a good tool for a single table of data. You can set the field separator and it will automatically split the fields for you so you can modify and print the output formatted the way you want. You can also print the table header in the BEGIN block and a summary in the END block (for example).

If you need multiple levels of fields I would use Perl which has a general split command that can split a string on any pattern. If you don't want to spend the time learning Perl you could still do this with multiple calls to awk. But it might be a little more "awkward".
1 members found this post helpful.
Old 02-27-2014, 05:59 PM   #4
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,495

Rep: Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099
Awk should be fine - I learned perl well before awk, but now use the latter almost exclusively for "quick and dirty" reports from logs.
match() should do similar in a single call (per input record).
Old 02-28-2014, 12:02 PM   #5
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,844

Rep: Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478
On the other hand, perl has much better table formatting capabilities.

But whichever one you want can do the job.


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
Sysklogd - Retention / generate report mj_official Linux - Newbie 3 09-26-2013 05:57 PM
Awstats will not generate any report? MrUmunhum Linux - Software 3 04-22-2010 03:21 PM
How to Generate Report in Freeradius mudresh Linux - Newbie 1 11-05-2009 04:26 AM
auto-generate email report guy_ripper Linux - Software 4 01-23-2008 11:07 PM
Generate Mail report kwtan Linux - Software 1 01-23-2006 05:41 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:35 AM.

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