From owner-freebsd-questions@FreeBSD.ORG Tue Apr 15 15:46:58 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 99AB537B401 for ; Tue, 15 Apr 2003 15:46:58 -0700 (PDT) Received: from wonkity.com (wonkity.com [65.173.111.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id B180443FA3 for ; Tue, 15 Apr 2003 15:46:57 -0700 (PDT) (envelope-from wblock@wonkity.com) Received: from wonkity.com (localhost [127.0.0.1]) by wonkity.com (8.12.9/8.12.9) with ESMTP id h3FMkuJI020913; Tue, 15 Apr 2003 16:46:56 -0600 (MDT) (envelope-from wblock@wonkity.com) Received: from localhost (wblock@localhost) by wonkity.com (8.12.9/8.12.9/Submit) with ESMTP id h3FMkukN020910; Tue, 15 Apr 2003 16:46:56 -0600 (MDT) Date: Tue, 15 Apr 2003 16:46:56 -0600 (MDT) From: Warren Block To: Peter Elsner In-Reply-To: <5.2.0.9.2.20030415085340.01bae4a0@mail.servplex.com> Message-ID: <20030415163837.R20819@wonkity.com> References: <5.2.0.9.2.20030415085340.01bae4a0@mail.servplex.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-questions@freebsd.org Subject: Re: dos2unix??? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Apr 2003 22:46:58 -0000 On Tue, 15 Apr 2003, Peter Elsner wrote: > #!/usr/bin/perl > # SCRIPT: dtox > # AUTHOR: Peter Elsner > # PURPOSE: Convert Text files from DOS to UNIX (remove ^M's) > # > > while (<>) { > if ($ARGV ne $OLDARGV) { > rename($ARGV, $ARGV . '.bak'); > open(ARGVOUT, ">$ARGV"); > select(ARGVOUT); > $OLDARGV=$ARGV; > } > s/^M//g; Um... ^M would mean an M at the start of a line. This should be s/\r//g; or use the tr operator: tr/\r//d; > % dtox filename > > A back up file is created filename.bak and then a new file is created with > the ^M's removed... The Perl -i and -p options make this kind of script much easier to write and debug: perl -i.bak -pe 'tr/\r//d' That's the whole thing. If you look up those options in man perlrun, you'll see they create almost the exact loop in the program above. A csh alias should work fine: alias dtox perl -i.bak -pe 'tr/\r//d' -Warren Block * Rapid City, South Dakota USA