bash one-liners with multiple pipes

daniel danstemporaryaccount-FFYn/CNdgSA at public.gmane.org
Tue May 11 17:47:11 UTC 2004


On May 11, 2004 12:55 pm, G. Matthew Rice wrote:
> Henry Spencer <henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org> writes:
> > What you *can* do, possibly at some cost in convenience, is try to roll
> > all the output processing into a single program.  In particular, note
> > that awk can do anything that grep and sed can do, so it might be
> > possible (if a little cumbersome) to just do "tail | awk".
>
> It doesn't solve the buffering problem but:
>
>          tail -f /some/log | awk '$7 !~ /\.(gif|png|css|jpg)/ {
>                  sub("&requestUrl=.*", "", $7);
>                  print $1, $7
>                 }'
>
> Should do it and it fixes a potential bug in his earlier example.
> The bug being that the first field [$1] is probably IP addresses but could
> also be domain names [such as i.am.a.gif.com ;)].

kickass.  thanks so much.  that's exactly what i'm looking for.  i'll have to 
alias this as "tailblog" or something.

> Even with fflush in awk, I still get the buffering.
>
> However, there's a bigger potential problem.  Is his version of tail going
> to notice when his log file gets truncated and/or moved out of the way?
> Something to test for, at least.

i'm not worried about this since (a) i don't rotate my logs and (b) it's just 
for when i feel like tailing it.  if for some reason i decided to rotate the 
log, i'd just re-run the script.

thanks so much.

-- 
"And the true threats of the 21st century are the ability for some rogue
leader to say to the United States, to Europe, to Russia herself, to Israel,
don't you dare move, don't you dare try to express your freedom, otherwise
we'll blow you up."

George W. Bush
July 20, 2001
BBC Interview

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list