Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dos2unix in /usr/bin woud be nice

57 views
Skip to first unread message

nos...@notreal.com

unread,
Nov 6, 2009, 10:04:30 PM11/6/09
to
I know what you are thinking. Why in the earth would a true Slacker
that stays away from DOS and MS products need with a "dos2unix" command.
Well it turns out it is very handy when writing bash scripts. If you
have a script that you run with cron that captures stdout results to a
file to mail using "cat" and "mailx", you sometime have a carriage
return embedded in it that results in email with the dreaded
"Application/OCTET-STREAM:" attachment that Pine cannot easily read. If
you instead run any resulting files from your script through dos2unix
before mailing them, it cleans the file up and it shows the text in the
body of the mail where it can be easily read.

I found dos2unix at "http://hany.sk/~hany/_data/hd2u/" and it was easy
to install, but it is one more thing you have to remember to do if you
do a fresh install.


Keith Keller

unread,
Nov 6, 2009, 10:20:40 PM11/6/09
to
On 2009-11-07, <nos...@notreal.com> <nos...@notreal.com> wrote:
> I know what you are thinking. Why in the earth would a true Slacker
> that stays away from DOS and MS products need with a "dos2unix" command.
> Well it turns out it is very handy when writing bash scripts.

The following is more or less equivalent to dos2unix (converting DOS
files, which use CRLF as line terminators):

perl -pi -e 's/\r//g' file.txt

To convert a Mac-format file (which IIRC some OS X editors still use),
which uses only CR as a line terminator:

perl -pi -e 's/\r/\n/g' file.txt

If you're using as a pipe, you can (probably) omit -i (untested). (I
don't think it hurts, though, also untested.)

--keith


--
kkeller...@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

Grant

unread,
Nov 6, 2009, 11:36:05 PM11/6/09
to
On Fri, 6 Nov 2009 22:04:30 -0500, <nos...@notreal.com> wrote:

>I know what you are thinking. Why in the earth would a true Slacker
>that stays away from DOS and MS products need with a "dos2unix" command.
>Well it turns out it is very handy when writing bash scripts. If you
>have a script that you run with cron that captures stdout results to a
>file to mail using "cat" and "mailx", you sometime have a carriage
>return embedded in it that results in email with the dreaded
>"Application/OCTET-STREAM:" attachment that Pine cannot easily read. If
>you instead run any resulting files from your script through dos2unix
>before mailing them, it cleans the file up and it shows the text in the
>body of the mail where it can be easily read.

Hmm, I been running mixed windows and linux on localnet since '97,
hardly ever face this issue.

>
>I found dos2unix at "http://hany.sk/~hany/_data/hd2u/" and it was easy
>to install, but it is one more thing you have to remember to do if you
>do a fresh install.

sed, tr, gawk, perl (as another mentioned) -- lots of ways to defeat
silly-dos crlf nonsense.

Grant.
--
http://bugsplatter.id.au

mtbr onmt

unread,
Nov 7, 2009, 1:14:40 AM11/7/09
to
On Nov 6, 7:04 pm, <nos...@notreal.com> wrote:
< . . . >

> I found dos2unix at "http://hany.sk/~hany/_data/hd2u/" and it was easy
> to install, but it is one more thing you have to remember to do if you
> do a fresh install.

next tested and works on Slackware 12.2

al@P5Q:~$ perl -MExtUtils::Command -e dos2unix ./dosfil.txt

perl is already on and same with Perl's ExtUtils::Command module

and same with dos2unix which is one of the commands/duties of
that particular perl module.

All of the above os already on.

doc. for that perl module:

http://search.cpan.org/~rkobes/ExtUtils-Command-1.16/lib/ExtUtils/Command.pm

--
mtbr

Robby Workman

unread,
Nov 7, 2009, 1:31:28 AM11/7/09
to
On 2009-11-07, <nos...@notreal.com> <nos...@notreal.com> wrote:


Is there something that fromdos(1) and/or todos(1) cannot do?

fromdos < infile > outfile

With a bit of creative scripting, you can make your own dos2unix and
unix2dos commands even.

-RW

Robert Komar

unread,
Nov 7, 2009, 2:05:02 AM11/7/09
to

It was probably about 10 years ago that dos2unix was replaced with
todos/fromdos in slackware. Get with the times, man! ;)

Cheers,
Rob Komar

Helmut Hullen

unread,
Nov 7, 2009, 2:16:00 AM11/7/09
to
Hallo, nospam,

Du meintest am 06.11.09:

> I found dos2unix at "http://hany.sk/~hany/_data/hd2u/" and it was
> easy to install, but it is one more thing you have to remember to do
> if you do a fresh install.

I found this "dos2unix"

alias dos2unix='recode ibmpc..lat1'

I found it under slackware 11, I found it under slackware 12 and under
slackware 13.

The only problem with "alias": it needs a shell, it seems to be invoked
as part of a profile.

I found this problem in the linux shell of "wsusoffline",

http://wsusoffline.net

(now it's fixed)

Viele Gruesse
Helmut

"Ubuntu" - an African word, meaning "Slackware is too hard for me".

nos...@notreal.com

unread,
Nov 7, 2009, 8:26:01 AM11/7/09
to
In article <dvt9f55tkqoel3bv1...@4ax.com>,
g_r_a...@bugsplatter.id.au says...

> On Fri, 6 Nov 2009 22:04:30 -0500, <nos...@notreal.com> wrote:
>
> >I know what you are thinking. Why in the earth would a true Slacker
> >that stays away from DOS and MS products need with a "dos2unix" command.
> >Well it turns out it is very handy when writing bash scripts. If you
> >have a script that you run with cron that captures stdout results to a
> >file to mail using "cat" and "mailx", you sometime have a carriage
> >return embedded in it that results in email with the dreaded
> >"Application/OCTET-STREAM:" attachment that Pine cannot easily read. If
> >you instead run any resulting files from your script through dos2unix
> >before mailing them, it cleans the file up and it shows the text in the
> >body of the mail where it can be easily read.
>
> Hmm, I been running mixed windows and linux on localnet since '97,
> hardly ever face this issue.


I have been running Slackware for about as long too, and I have seen the
problem before but it was infrequent and never bothered me enough to do
anything about it - until now. I really wanted to have the results of
a script mailed to me and I use Alpine (Pine) as my mail reader so I
needed a solution.

> >I found dos2unix at "http://hany.sk/~hany/_data/hd2u/" and it was easy
> >to install, but it is one more thing you have to remember to do if you
> >do a fresh install.
>
> sed, tr, gawk, perl (as another mentioned) -- lots of ways to defeat
> silly-dos crlf nonsense.

I thank you, and all the other people who responded as well, with
suggestions. I was unaware of some of them (todos/fromdos for one),
and not clever or imaginative enough to consider others on my own (e.g.,
sed). The dos2unix was the first thing I came across after identifying
the problem, and it solved it very neatly with not much mental strain on
my part in two lines.

dos2unix results.txt
cat results.txt | mail -s Results user

My thanks again to all who responded and I won't expect dos2unix to show
up in /usr/bin anytime soon ;-).


>
> Grant.
>

Jim Diamond

unread,
Nov 7, 2009, 11:28:54 AM11/7/09
to
On 2009-11-07 at 09:26 AST, <nos...@notreal.com> <nos...@notreal.com> wrote:

> I was unaware of some of them (todos/fromdos for one), and not
> clever or imaginative enough to consider others on my own (e.g.,
> sed). The dos2unix was the first thing I came across after
> identifying the problem, and it solved it very neatly with not much
> mental strain on my part in two lines.

> dos2unix results.txt
> cat results.txt | mail -s Results user

Here is some less typing strain :-) (Look up the acronym "UUOC".)

mail -s Results user < results.txt

Cheers.
Jim

Keith Keller

unread,
Nov 7, 2009, 3:37:43 PM11/7/09
to

Well, if you're going to play bash golf:

dos2unix < results.txt | mail -s Results user

Jim Diamond

unread,
Nov 8, 2009, 12:13:20 PM11/8/09
to
On 2009-11-07 at 16:37 AST, Keith Keller <kkeller...@wombat.san-francisco.ca.us> wrote:
> On 2009-11-07, Jim Diamond <Jim.D...@nospam.AcadiaU.ca> wrote:
>> On 2009-11-07 at 09:26 AST, <nos...@notreal.com> <nos...@notreal.com> wrote:
>>
>>> dos2unix results.txt
>>> cat results.txt | mail -s Results user
>>
>> Here is some less typing strain :-) (Look up the acronym "UUOC".)
>>
>> mail -s Results user < results.txt
>
> Well, if you're going to play bash golf:
>
> dos2unix < results.txt | mail -s Results user

Why mention bash specifically? Maybe the OP (or some other follower)
is using some other shell.

Golf??

Anyway, you are right, that is shorter, but only if the OP doesn't
actually want to convert the file and use it for other things.

Cheers.

Jim

0 new messages