From owner-freebsd-questions@FreeBSD.ORG Tue Sep 1 20:51:58 2009 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 BC8BC106566C for ; Tue, 1 Sep 2009 20:51:58 +0000 (UTC) (envelope-from freebsd@optimis.net) Received: from mail.optimis.net (mail.optimis.net [69.104.191.124]) by mx1.freebsd.org (Postfix) with ESMTP id 90DB48FC1E for ; Tue, 1 Sep 2009 20:51:58 +0000 (UTC) Received: from marvin.optimis.net (marvin.optimis.net [192.168.1.3]) by mail.optimis.net (8.14.3/8.14.2) with ESMTP id n81Ktn7g008457 for ; Tue, 1 Sep 2009 13:55:50 -0700 (PDT) (envelope-from freebsd@optimis.net) Received: from marvin.optimis.net (localhost [127.0.0.1]) by marvin.optimis.net (8.14.3/8.14.3) with ESMTP id n81Kq1eN006660 for ; Tue, 1 Sep 2009 13:52:01 -0700 (PDT) (envelope-from freebsd@optimis.net) Received: (from george@localhost) by marvin.optimis.net (8.14.3/8.14.3/Submit) id n81Kq1GB006659 for freebsd-questions@freebsd.org; Tue, 1 Sep 2009 13:52:01 -0700 (PDT) (envelope-from freebsd@optimis.net) Date: Tue, 1 Sep 2009 13:52:01 -0700 From: George Davidovich To: freebsd-questions@freebsd.org Message-ID: <20090901205201.GA6126@marvin.optimis.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) Subject: Re: remove newlines from a file 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: Tue, 01 Sep 2009 20:51:58 -0000 On Tue, Sep 01, 2009 at 06:03:19PM +0000, Paul Schmehl wrote: > I found a sed tutorial once that did this, but I can't seem to find it > again. You're probably thinking of "Useful One-Line Scripts for Sed": http://sed.sourceforge.net/sed1line.txt A good follow-up: http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained > I have a file with multiple lines, each of which contains a single ip > followed by a /32 and a comma. I want to combine all those lines into > a single line by removing all the newline characters at the end of > each line. > > What's the best/most efficient way of doing that in a shell? A sed solution would be sed -e :a -e '$!N; s/\n/ /; ta' my_file Other (easier to remember) solutions could include: tr -d '\n' < my_file tr '\n' ' ' < my_file echo $(cat my_file) # not so useless use of cat! paste -s my_file while read line; do joined="$joined $(echo $line)" done < my_file echo $joined Lots of options, of course. Even more with Perl. -- George