This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Spaces Problem
David Korn wrote:
> >From: mike corbeil ordinary user account
> [mailto:mcorbeil@NetRevolution.com]
> >Sent: 25 October 2000 19:10
> >
> >There's usually, for Unices, a utility program named dos2unix which can
> >be used to convert dos text files to Unix format, and it works for
> >Linux, too.
>
> ...Which if you don't have it, can be replaced by the following command:
>
> tr '^M' '' <[infile] >[outfile]
>
> or for a slightly flashy version that safely overwrites the original file
>
> tr '^M' '' <[infile] >/tmp/tmp.txt && mv /tmp/tmp.txt [infile]
>
> You may want to put these into shell scripts or aliases.
>
> DaveK
Yes, tr is an alternative to sed for this purpose, as would be Perl, however
I didn't bother providing the code example for sed, because it wouldn't be
needed if the person had dos2unix, or what ever the name
is. I expected the person to write back with "how do you do it in sed, for
I don't have dos2unix?", if they didn't have dos2unix.
Kind of like is often said in the Perl community, there is usually more than
one way to do it, what ever it is. TIMTOWTDI (there is more than one way to
do it - no U for usually).
Using tr is a tiny bit shorter than using sed, and even short wrt using Perl
for this, but I don't usually worry about one or two characters more or less
either way. At the end of the week, or even day, saving a few characters
here or there doesn't amount to more than a few seconds saved.
Wrt using aliases, people may also create functions in their .bashrc (e.g.,)
file, for more complicated purposes. However, alias would be better for the
tr command you gave an example of. If the person wanted to add a loop
construct, then either an alias or a function would be both worth looking at
or consdering. In that case, both could also be used, with the alias
referring to the function, if the person wanted to give the function a
different or longer name (I haven't done looping in an alias, but imagine
this can be done). This para is or may be more than extra for this thread
though, but maybe not.
This may beef up this now tutorial a little, for TIMTOWTDI is a very useful
paradigm and can even provide a little more sanity.
>
> --
> SEAL Team 6 World Trade Center Serbian Cocaine [Hello to all my fans
> in domestic surveillance] cracking KGB nuclear arrangements CIA
> counter-intelligence smuggle fissionable ammunition SDI
Interesting and a good laugh.
mike