Re: [SLUG] Conversion question

From: Paul M Foster (paulf@quillandmouse.com)
Date: Wed Jan 17 2007 - 17:05:07 EST


Chuck Hast wrote:
> On 1/17/07, Eben King <eben01@verizon.net> wrote:
>> On Wed, 17 Jan 2007, Chuck Hast wrote:
>>
>> > On 1/17/07, Eben King <eben01@verizon.net> wrote:
>> >> On Wed, 17 Jan 2007, Paul M Foster wrote:
>> >>
>> >> > Chuck Hast wrote:
>> >> >
>> >> > For clarification:
>> >> >
>> >> > Line endings in Unix/Linux: LF (0x0a)
>> >> > Line endings in DOS/Windows: CR/LF (0x0d 0x0a)
>> >> > Line endings in Mac: CR (0x0d)
>> >> >
>> >> > Not quite sure why you're using a script. Just do:
>> >> >
>> >> > cat filename | dos2unix
>> >>
>> >> UUOC.
>> >>
>> >> dos2unix < filename
>> >
>> > I am guessing in this case it would be
>> > unix2dos <filename?
>>
>> The file has Unix-style line endings (LF), and you want MSDOS-style
>> endings
>> (CR+LF), so yes.
>>
>> If you don't have those, you can change the endings appropriately with
>> sed
>> and tr.
>>
>> -
>
> Yep, but I have two utilities and unix2dos is the one to go from LF to
> CR.+LF,
> so figured I needed to use that one.
>
>

Maybe some more fundamental advice might help (yes, I realize you solved
the problem, Chuck).

My original advice was:

cat filename | unix2dos

You probably realize that 'cat' just "concatenates" the file in question
to 'stdout', which is normally the screen. When you put a '|' pipe there
it connects the output of your 'cat' command with the input of the next
command, in this case, unix2dos.

Some commands are set up to gobble input from another program, like
'unix2dos'. Others aren't, like 'firefox'. So if you want to get them to
gobble the input from something else (like the contents of a file), you
have to do something that sends the output to the command. I recommended
'cat'.

Eben made the comment that this was 'UUOC', or "useless use of cat", and
he's right. You can accomplish the same thing by

unix2dos < filename

It's a simpler way of accomplishing the same thing. It has less overhead
as it doesn't have to call the 'cat' command. It simply dumps the
contents of the file and the '<' (less-than symbol) tells Linux where to
send that output, in this case, to the 'unix2dos' command.

You can also have something like this:

unix2dos < filename > different_filename

which runs the filename through unix2dos, and then dumps the output in a
file named 'different_filename'.

Or

unix2dos < filename | dos2unix

which would "pipe" the results of 'unix2dos < filename' to the command
'dos2unix', which should output exactly the file you started with.

The rules for using <, > and | are sometimes a little hard to follow,
but you get the idea.

Paul

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:38:21 EDT