Date: Thu, 21 Aug 2008 15:49:17 +0200 (CEST) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-questions@FreeBSD.ORG, steve@ibctech.ca Subject: Re: sed/awk, instead of Perl Message-ID: <200808211349.m7LDnHHX000891@lurza.secnetix.de> In-Reply-To: <48AD63B7.8090107@ibctech.ca>
next in thread | previous in thread | raw e-mail | index | archive | help
Steve Bertrand wrote: > To put it plainly, can anyone, if it's possible, provide a single line > sed/awk pipeline that can: > > - read email addresses from a file in the format: > > user.name TAB domain.tld > > - convert it to: > > user_name@example.com With awk(1): awk '{sub(/\./, "_", $1); print $1 "@example.com"}' With sed(1) (you have to replace "^T" with a real tab!): sed 's/^\(.*\)\.\(.*\)^T.*/\1_\2@example.com/' With tr(1) + sed(1): tr '.\t' '_@' | sed 's/@.*/@example.com/' Personally I like the last solution best, because it's short and easy to understand. BTW, all of the above command read from stdin and write to stdout, so you can use shell redirection to read from a file and/or write to a file. There is no need to use cat(1). Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd With Perl you can manipulate text, interact with programs, talk over networks, drive Web pages, perform arbitrary precision arithmetic, and write programs that look like Snoopy swearing.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808211349.m7LDnHHX000891>