From owner-freebsd-questions@FreeBSD.ORG Sun Sep 30 23:34:44 2007 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 927C816A417 for ; Sun, 30 Sep 2007 23:34:44 +0000 (UTC) (envelope-from perrin@apotheon.com) Received: from outbound-mail-32.bluehost.com (outbound-mail-32.bluehost.com [69.89.18.152]) by mx1.freebsd.org (Postfix) with SMTP id 6B8B713C447 for ; Sun, 30 Sep 2007 23:34:44 +0000 (UTC) (envelope-from perrin@apotheon.com) Received: (qmail 7078 invoked by uid 0); 30 Sep 2007 23:34:44 -0000 Received: from unknown (HELO box183.bluehost.com) (69.89.25.183) by mailproxy2.bluehost.com with SMTP; 30 Sep 2007 23:34:44 -0000 Received: from c-24-9-123-251.hsd1.co.comcast.net ([24.9.123.251] helo=demeter.hydra) by box183.bluehost.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1Ic8J9-0003BU-EM for freebsd-questions@freebsd.org; Sun, 30 Sep 2007 17:34:43 -0600 Received: from demeter.hydra (localhost [127.0.0.1]) by demeter.hydra (8.13.6/8.13.6) with ESMTP id l8U1sKwW025229 for ; Sat, 29 Sep 2007 19:54:20 -0600 (MDT) (envelope-from perrin@apotheon.com) Received: (from ren@localhost) by demeter.hydra (8.13.6/8.13.6/Submit) id l8U1sK8q025228 for freebsd-questions@freebsd.org; Sat, 29 Sep 2007 19:54:20 -0600 (MDT) (envelope-from perrin@apotheon.com) X-Authentication-Warning: demeter.hydra: ren set sender to perrin@apotheon.com using -f Date: Sat, 29 Sep 2007 19:54:19 -0600 From: Chad Perrin To: FreeBSD Questions Message-ID: <20070930015419.GC24643@demeter.hydra> Mail-Followup-To: FreeBSD Questions References: <21079.67.171.53.31.1191004462.squirrel@admintool.trueband.net> <20070928140159.M29117@wonkity.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070928140159.M29117@wonkity.com> User-Agent: Mutt/1.4.2.3i X-Identified-User: {737:box183.bluehost.com:apotheon:apotheon.net} {sentby:bopbeforesmtp 24.9.123.251 authed with apotheon.com} X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box183.bluehost.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [737 12] / [47 12] X-AntiAbuse: Sender Address Domain - apotheon.com Subject: Re: Adding CR/LF 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: Sun, 30 Sep 2007 23:34:44 -0000 On Fri, Sep 28, 2007 at 03:09:52PM -0600, Warren Block wrote: > On Fri, 28 Sep 2007, jhall@vandaliamo.net wrote: > > >The output I would like to see is: > >test1 > >test2 > >test3 > > String manipulation in sh is painful at best. Any of the scripting > languages are better at this. A Ruby example, almost a direct translation of the sh code: #!/usr/local/bin/ruby filenames = %w[test1 test2 test3] filenames.each { |fn| print file_list << fn } That'll give output that looks like: test1 test2 test3 . . . using CRLF line endings. If you actually just want newlines in the Unix style, of course, you can just do this instead of the filenames.each line: puts filenames That'll automatically output each element of the filenames array with a newline at the end. In Perl, that code (for the same output) might look something like this: #!/usr/local/bin/perl use strict; use warnings; my @filenames = qw(test1 test2 test3); for my $fn (@filenames) { print $fn, "\r\n" }; Again, in Perl you can do this more easily if Unix-style newlines are what you want instead of CRLF. In the case of Perl, you'd use the -l option in the shebang line: #!/usr/local/bin/perl -l . . . and replace the for loop with this: print for @filenames; Of course, this is all moot if you actually have a specific need for using sh instead of Ruby or Perl. By the way, though, I think the CRLF characters were backwards in the original post of this thread, which used "\n\r". I'm pretty sure it's "\r\n" as I've done it. I may just be having a stupid day, though, and be getting them backwards myself. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] Ben Franklin: "As we enjoy great Advantages from the Inventions of others we should be glad of an Opportunity to serve others by any Invention of ours, and this we should do freely and generously."