From owner-freebsd-questions@FreeBSD.ORG Thu Aug 21 13:49:19 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 90378106567B for ; Thu, 21 Aug 2008 13:49:19 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (unknown [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 0BAD78FC2F for ; Thu, 21 Aug 2008 13:49:18 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.2/8.14.2) with ESMTP id m7LDnHii000892; Thu, 21 Aug 2008 15:49:17 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.2/8.14.2/Submit) id m7LDnHHX000891; Thu, 21 Aug 2008 15:49:17 +0200 (CEST) (envelope-from olli) Date: Thu, 21 Aug 2008 15:49:17 +0200 (CEST) Message-Id: <200808211349.m7LDnHHX000891@lurza.secnetix.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG, steve@ibctech.ca In-Reply-To: <48AD63B7.8090107@ibctech.ca> X-Newsgroups: list.freebsd-questions User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.3-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Thu, 21 Aug 2008 15:49:17 +0200 (CEST) Cc: Subject: Re: sed/awk, instead of Perl X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@FreeBSD.ORG, steve@ibctech.ca List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Aug 2008 13:49:19 -0000 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.