LinuxQuestions.org
Help answer threads with 0 replies.
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 02-27-2014, 11:30 AM   #1
petemac117
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
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
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
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,667

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
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
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,059

Rep: Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916Reputation: 1916
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
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

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

But whichever one you want can do the job.
 
  


Reply


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


All times are GMT -5. The time now is 10:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration