Cat command does not respect new line

Here's my script

echo "1" >>hello.txt
echo "2" >>hello.txt
echo "3" >>hello.txt
mailx -s "Check Status" #myteam@mycomp.com<hello.txt

In Outlook I see EMail body as

when I want it to be

can you please suggest ?

What is the arrangement of this text file when you view it on the UNIX system?

Outlook is infamous for ignoring all formatting and arranging text as it pleases. Sometimes it takes <pre> </pre> tags wrapped around text to force it to do otherwise.

cat -ev hello.txt

1$
2$
3$

So, the text file is good. Each entry is on a new line.

Any suggestion ?

The thread title is VERY misleading - cat WILL act correctly on newline chars!
PLEASE make sure the thread title does reflect the problem in your future posts.

Exactly, I realized this just as I posted the query.

But, noway to correct that.

I was thinking cat hello.txt | maix -s "Alert" ........ would help... but it does not and that's where that cat shows in the title.

Please correct it if you feel like.

As you are talking of outlook - which is not UNIX...
I would try

cat hello.txt| $ux2dos |\mailx -s "Alert" ...... 

$ux2dos is path and correct name of the utility as you have not mentioned your OS...

I tried this but it still fails...

cat hello.txt | $dos2unix |\mailx -s "Alert" myemail@mycomp.com
                   
 Null message body; hope that's ok

My system details:

uname -a
Linux mymac 3.10.0-327.36.1.el7.x86_64 #1 SMP Wed Aug 17 03:02:37 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

Please suggest.

$dos2unix is a variable; that might work if a correct command is assigned to this var. Were it dos2unix , it would be the wrong direction. What's the output of your pipe without mailx... ? I think dos2unix doesn't work on stdin and stdout but needs two - possibly identcal - filenames to read from and write to.

I mentionned $ux2dos and not dos2unix... and as Rudi mentionned its a variable that is why I said is twas the pathand correct name of the utility as it cand differ depending of OS flavour...
You are converting unix file to dos sytem not the other way round.... please pay attention to what users post before replying "its not working"....

I have it as variable because using scripts/jobs doing the same on different OS I have to put in variable what changes depending OS, some systems I had to write my own version... so you can have custom ux2dos, standard ux2dos and standard unix2dos etc.... and depending of implemtation they will not always be in /usr/bin ...

I use it like that ( piped for mail because we have outlook...) but my ux2dos is a custom complied by me... So you would have to chack first what is the result of the pipe to see if it work ( mosts cases ...) because I cannot guarantee ( tested mostly on true UNIX systems... but not on linux...)

Hi.

The dos2unix package:

OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie) 
dos2unix 6.0.4 (2013-12-30)

contains a few utilities. One, unix2dos , can work like this:

$ cat z5 | tee >(od -bc > o1) | unix2dos | od -bc > o2
$ head o?

producing:

==> o1 <==
0000000 141 012 142 012 143 012
          a  \n   b  \n   c  \n
0000006

==> o2 <==
0000000 141 015 012 142 015 012 143 015 012
          a  \r  \n   b  \r  \n   c  \r  \n
0000011

If you don't have the dos2unix package, then you might be able to use:

$ cat z5 | tee >(od -bc > o1) | perl -pe 's/\012/\015\012/g' | od -bc > o2
$ head o?
==> o1 <==
0000000 141 012 142 012 143 012
          a  \n   b  \n   c  \n
0000006

==> o2 <==
0000000 141 015 012 142 015 012 143 015 012
          a  \r  \n   b  \r  \n   c  \r  \n
0000011

Best wishes ... cheers, drl

Hi,

Have you tried like below? If not please try once, it might help.

echo "1\n" >>hello.txt
echo "2\n" >>hello.txt
echo "3\n" >>hello.txt

Thanks.

Does not Help.

When i run the command with $ux2dos i get

Null message body; hope that's ok

Also cat hello.txt| $ux2dos reveals no output. Only cat hello.txt does.

---------- Post updated at 05:11 AM ---------- Previous update was at 05:00 AM ----------

Does not Help !!

cat hello.txt 
1\n
2\n
3\n

Please be a bit creative and try to adapt the hints/proposals given to your problem. WHAT is the contents of the $ux2dos variable? If it is not the empty string, what is the result of running it against a simple example file? What is the result of it running in a pipe but NOT piped to a further command?

$ux2dos is empty.

Also, i do NOT wish to use or even have perl

I also tried @madman's suggestion of

Also dos2unix command is NOT found on my Linux

I then proceeded to do this but no success :frowning:

tr -d '\r' < hello.txt > hellow.txt1
mv hello.txt1 hello.txt

I dont know if there are any more suggestions to try.

So - what do you expect an empty command to perform?

There have been presented a lot of suggestions in the course of this thread. Did you try them all, maybe adapting them in a way or another?

What is the result of

dos2unix hello.txt

(please note: NO $ sign in front of the command)

dos2unix hello.txt

command not found.

Please DON'T edit posts (here #14) after people commented on them pulling the rug from under their feet!

I'm afraid we're out of options here as your system is not known to anybody except you and you're not providing too many informations. Last try from my side:

sed 's/$/\r/' hello.txt

Check the result by piping it through

od -ctx1

Means : YOU, not us as we know your system, are to give that variable its correct value, so of cours if you did not do your part - It just cant work...

I have mentioned my OS

uname -a
Linux mymac 3.10.0-327.36.1.el7.x86_64 #1 SMP Wed Aug 17 03:02:37 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

I dont know where and how to find or set ux2dos

Please suggest.

---------- Post updated at 07:49 AM ---------- Previous update was at 07:43 AM ----------

When I try your suggestion

sed 's/$/\r/' hello.txt | mailx -s "Alert | Disk SLOW | Copy taking overtime | Take ACTION" mymail@mycom.com

I get an email with an attachment ATT00001.bin which has the Body in good format.

But, I need the same as an email body and not as an attachment.

Typing which ux2dos ; which unix2dos should answer, if nothing then the utilities are not installed...
Linux have many flavours and some like debian doont install theses utilities by default...
I have such a box here so I tested:

alias ux2dos='sed "s/^M\{1,\}$//" | sed "$ s/^Z//"'

Then I tested like this

cat deutsch.txt|ux2dos 

And its works...
So now you can search previous posts in this thread to find what was posted on how to finish or is that too much effort for you?