From owner-freebsd-questions@FreeBSD.ORG Thu Aug 21 12:54:31 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D01D1065674 for ; Thu, 21 Aug 2008 12:54:31 +0000 (UTC) (envelope-from joji@eskimo.com) Received: from ultra5.eskimo.com (ultra5.eskimo.com [204.122.16.68]) by mx1.freebsd.org (Postfix) with ESMTP id 15FEC8FC20 for ; Thu, 21 Aug 2008 12:54:30 +0000 (UTC) (envelope-from joji@eskimo.com) Received: from eskimo.com (eskimo.com [204.122.16.13]) by ultra5.eskimo.com (8.14.3/8.14.0) with ESMTP id m7LCsT1f017332; Thu, 21 Aug 2008 05:54:29 -0700 Received: (from joji@localhost) by eskimo.com (8.9.1a/8.9.1) id FAA28228; Thu, 21 Aug 2008 05:54:29 -0700 (PDT) Date: Thu, 21 Aug 2008 05:54:29 -0700 From: Joseph Olatt To: Steve Bertrand Message-ID: <20080821055429.A26910@eskimo.com> References: <48AD63B7.8090107@ibctech.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <48AD63B7.8090107@ibctech.ca>; from steve@ibctech.ca on Thu, Aug 21, 2008 at 08:46:47AM -0400 Cc: freebsd-questions@freebsd.org Subject: Re: sed/awk, instead of Perl X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Aug 2008 12:54:31 -0000 On Thu, Aug 21, 2008 at 08:46:47AM -0400, Steve Bertrand wrote: > I'm frequently having to modify/convert email addresses from one > format/domain to another. > > Usually, I slap together a quick Perl script to do this for me. I don't > do it frequently enough to keep track which one of my scripts does this > for me, so I'm continuously re-inventing the wheel. > > Some of the time, I use sed/awk to do this, but that usually requires a > few passes over a few files. > > 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 > > - write it back to either a new file, the original file, or to STDOUT > > Regards, > > Steve Try the following: cat t.txt | awk -F\t '{split($1, arr, "."); printf("%s_%s@%s\n", arr[ 1], arr[2], $2);}' where t.txt: john.doe example.com regards, joseph