Scripting Question

H. S. hs.samix at gmail.com
Sat Feb 14 15:32:24 UTC 2009


On Sat, Feb 14, 2009 at 4:36 AM, Matthew Flaschen <
matthew.flaschen at gatech.edu> wrote:

> H.S. wrote:
>
> >
> > More concise (given the order of data fields is constant) and probably
> > more efficient and better (the following is one long line):
> >
> > #---------------------------------------------
> > $> cat full.db | while read line; do echo "${line}" |awk 'BEGIN { FS =
> > "," }; {print $2, $3, $4,  $58}' | tr -d '"'; done
>
> There are a few issues.  There's no need for cat, read line...done, tr,
> or echo (shell scripting is slow, especially when you fork multiple



Ah, right.



>
> processes for every line).  This didn't handle all the emails and that's
> the wrong field number.  And it doesn't output in CSV format.  Finally,
>

I ran this command on a file where I pasted copies of  the line OP posted
and got the name parts and the email. I did not search for more emails
neither did I check for empty emails.



> the above prints every line, not only those with emails.  So I get:
>
> gawk -F, '{ if ( match($57$59$61, "@") ) print
> $2","$4","$57","$59","$61};' contacts.txt>processed_contacts.txt
>
> That's all one line.
>

Very nice. Thanks a ton!

Regards.



>
> Matt Flaschen
>
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20090214/640710dc/attachment.html>


More information about the ubuntu-users mailing list