General
Showing results for 
Search instead for 
Do you mean 

Is there a dos2unix command in HP?

Occasional Visitor

Is there a dos2unix command in HP?

I'm trying to find a command in HP that will convert a dos file to unix by
removing the ^M's in the file - similiar to the dos2unix command in sun.

If anyone knows of such a command in HP, please let me know. I really
appreciate it.

Thanks,
Connie
5 REPLIES
Regular Advisor

Re: Is there a dos2unix command in HP?

If all you need to do is remove the "^M" at the end of lines, use:

sed 's/^M//' infile > outfile

"^M" is generated by (ctrl-v, ctrl-m)
Occasional Visitor

Re: Is there a dos2unix command in HP?

We made this script whith ed:

#!/usr/bin/sh
PATH=/usr/bin; p0=${0##*/}
v=; [[ "$1" = -v ]] && { v=.; shift;}
[[ $#.$p0 != 1.d2u && $#.$p0 != 1.u2d ]] &&
{ cat <<-. >&2
End-of-line style direct file converter - using ed (DOS<->UX formats)

Usage: d2u [-v] {file} to convert DOS->UX (CR+LF->LF)
u2d [-v] {file} to convert UX->DOS (LF->CR+LF)

-v for verbose output (echoes # of lines)
.
exit 2;}
[[ ! -f $1 || ! -r $1 || ! -w $1 ]] &&
{ cat <<-. >&2
$p0 -- $1 not regular+readable+writable:
$(ls -ld $1 2>&1)
.
exit 1;}
a=$(grep -c "^M$" $1); l=$(wc -l <$1)
[[ $l = 0 ]] && { [[ -n $v ]] && echo "$p0 -- $1: no lines"; exit 0;}
if [[ $p0 = u2d ]] ; then
if [[ $a != 0 ]] ; then
x=already; [[ $a != $l ]] && x=partially
echo "$p0 -- $1 $x in DOS-format">&2; exit 1
fi
s=DOS; echo "1,\$s/\$/^M/\nw\nq"|ed -s $1; e=$?
else # [[ $p0 = d2u ]]
[[ $a = 0 ]] && { echo "$p0 -- $1 already in UX-format">&2; exit 1;}
s=UX; echo "1,\$s/^M\$//\nw\nq"|ed -s $1; e=$?
fi
[[ $e = 0 && -n $v ]] &&
{ v=s; [[ $l = 1 ]] && v=; echo "$p0 -- $1: $l line$v ($s-format)";}
exit $e
Occasional Visitor

Re: Is there a dos2unix command in HP?

Hello,

I believe the command you're looking for is /usr/bin/dos2ux.

Regards,
Claire Ruben
Regular Advisor

Re: Is there a dos2unix command in HP?

If you do :

swlist -l product | grep DOS

you should see the following if you have the MSDOS utilities installed::

MSDOS-Utils B.10.20 MSDOS-Utils

If so, then there are various dos commands that will help you, including the
dos2ux command.
Occasional Contributor

Re: Is there a dos2unix command in HP?

If all you are having a problem with is the ^M's another solution would be to
transfer your text files as binary then there are no ^M in the file anyway