Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Nov 2001 23:30:17 +0200
From:      Giorgos Keramidas <charon@labs.gr>
To:        David Loszewski <stealth215@mediaone.net>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: ^M on end of lines
Message-ID:  <20011108233017.A548@hades.hell.gr>
In-Reply-To: <001a01c16508$e4623670$3000a8c0@sickness>
References:  <169116798405.20011103214209@telus.net> <001a01c16508$e4623670$3000a8c0@sickness>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Nov 04, 2001 at 03:15:40AM -0500, David Loszewski wrote:
> How bout if I wanna do it directories at a time? Like a whole bunch of
> directories?

The second suggestion, using tr(1) to 'delete' the \015 character is
easy to wrap in a script that does this automagically for you.  In
fact, a script that puts together the right tools to do your job is
probably the best way to do this.  You can filter all the files that
match '^M' with a combination of find, grep and other standard FreeBSD
tools.

Hell you can even make an ex(1) script and do the equivalent
of `editing the file' in a non-interactive way.

Here's a sample session from a test I just did to convert a file
called "hello.txt" from DOS format to Unix format.

    > cat -e hello.txt
    hello world^M$
    > cat ~/scripts/dos2unix.ex
    %s/^M/g
    :wq
    > ex -c ":so dos2unix.ex" hello.txt

    hello.txt: 1 lines, 1 characters
    > cat -e hello.txt
    hello world$
    >

Since `editing' a file to remove ^M characters can be done with ex(1)
and our simple dos2unix.ex script, and you have saved dos2unix.ex in
your HOME/scripts directory (haven't you?) here's a command line that
will convert all the *.txt files under ~/doc to Unix format:

    > find ~/doc -name '*.txt' |\
      xargs -1 ex -c ":so $HOME/scripts/dos2unix.ex"

And that's just one of a billion ways to do this.  You can probably
find easier and faster ways, or tools that will do everything you want
without all this `scripting madness'.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011108233017.A548>