Bill East on 22 May 2013 21:36:25 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] 2013-05-21 PLUG W follow-up


On Tue, May 21, 2013 at 1:04 AM, JP Vossen <jp@jpsdomain.org> wrote:
Thanks to Walt for an interesting look at NumPy and SciPy.


We also talked about formatting output from bash scripts.  I suggested plain old 'echo' or 'printf' commands.  Note that 'printf' is POSIX but 'echo' is not, and 'echo' *does* behave differently by default on various different systems.  E.g. on some systems "\n" is expanded to a newline while on others (like Linux) you need to use 'echo -e' (but see "xpg_echo" as well [1]).  Or you can output tab delimited or CSV output and import into a spreadsheet.  Someone also mentioned the 'fmt' command, which can be useful.  The 'fmt' and possibly 'column', 'colrm', 'awk' and 'cut' commands may also be of interest.  When I know I'm going right into a spreadsheet though, I just do tab delimited output like 'echo -e "Foo\tBar\tbaz"'.  It's really easy...

I'm writing to a temp file which then just gets mailxed to the end users, one hesitation I have about exporting to Excel is that then they have to take the extra step of opening the spreadsheet. I got a few minutes at the end of the day to play with some of this, and column -t did, really, exactly what I wanted to when I'm doing, for example

grep string logfile.file | awk '{print $1, $2, $[NF-1]}' | column -t
(not 100% on the syntax but it's like that)

Now the next thing I'm looking at is combining outputs, for example pulling IPs out of the file, say
grep string logfile.file | awk '{print $5}' | sort | uniq -c | sort, saving that off to variables, doing lookups on the IPs (dig -x +short) and then returning the count, ip and fqdn. The output I have now is generated with printf and looks something like

4    10.11.12.13     dns.name.one
2     8.8.8.8           another.dns.name
2     207.111.106.151          yet.another.name
etc.

Obviously it's OK until you get a longer IP address and then it gets less pretty. The problem is right now that I'm looping through the output from the first command (stored with either an array or a temp file) and printing the output line-by-line, I guess what I need to do to use column is store all the output in yet one more array or file and then run column on that, or else find some other way to clean up the output so that it comes out equally justified line-by-line.
 
p.s. - I asked on Facebook if Baz Luhrmann has older siblings named Foo and Bar but nobody answered.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug