Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Feb 2003 00:20:09 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Tijl Coosemans <tijl@ulyssis.org>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: cat
Message-ID:  <20030226222009.GB78804@gothmog.gr>
In-Reply-To: <20030226175613.5e61f45e.tijl@ulyssis.org>
References:  <20030226175613.5e61f45e.tijl@ulyssis.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2003-02-26 17:56, Tijl Coosemans <tijl@ulyssis.org> wrote:
> I want to remove CRs from text files so what I did is this:
>
> cat filename | tr -d '\r' > filename
>
> However, I often end up with an empty file. Just out of
> interest, somebody who knows why that is?

The shell opens filename for input and then attempts to reopen it once
more for output, at the same time.  The '>' operator truncates the
file.  You will get much better and more predictable results if you
use a temporary file to store the intermediate result of tr(1):

	$ tr -d '\r' < filename > filename.tmp
	$ mv filename.tmp filename

- Giorgos

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?20030226222009.GB78804>