[RndTbl] I just found a use for paste(1)!

Adam Thompson athompso at athompso.net
Sun Jan 17 18:37:09 CST 2010


OK, I've now used paste(1) about /three/ times in my life...

To re-flatten the output of egrep into a single line, as in:

     egrep -e '^Date:|^From:|^Subject:' $mailfile | paste -d'|' - - -

Specifically, I'm working on Maildir-style files so I don't have to 
worry about "losing synchronization" if one of the headers is missing 
for some reason, and the names of the files are contained in the file 
"0006966d83811cd33a120e436a67d312".

so:

     for i in $(cat 0006966d83811cd33a120e436a67d312 ); do
         (echo $i|cut -d'/' -f2 ; egrep '^Date:|^From:|^Subject:' ../$i 
) | paste -d'|' - - - - ;
     done

produces output like:

     .DNS|Date: Fri, 5 Jun 2009 21:16:22 -0400 (EDT)|From: "easyDNS 
Support" <support at easydns.com>|Subject: [easyDNS] Automated 30 day 
renewal reminder 2009-07-05
     .DNS|Date: Fri, 5 Jun 2009 21:16:22 -0400 (EDT)|From: "easyDNS 
Support" <support at easydns.com>|Subject: [easyDNS] Automated 30 day 
renewal reminder 2009-07-05

which I can then feed into the next stage of parsing.

-Adam

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.muug.mb.ca/pipermail/roundtable/attachments/20100117/9253397a/attachment.html 


More information about the Roundtable mailing list