Cat command does not respect new line

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Cat command does not respect new line
# 8  
Old 11-03-2016
$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.
# 9  
Old 11-03-2016
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...)

Last edited by vbe; 11-03-2016 at 04:08 PM..
# 10  
Old 11-03-2016
Hi.

The dos2unix package:
Code:
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:
Code:
$ cat z5 | tee >(od -bc > o1) | unix2dos | od -bc > o2
$ head o?

producing:
Code:
==> 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:
Code:
$ 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
# 11  
Old 11-04-2016
Hi,

Have you tried like below? If not please try once, it might help.
Code:
echo "1\n" >>hello.txt
echo "2\n" >>hello.txt
echo "3\n" >>hello.txt

Thanks.
# 12  
Old 11-07-2016
Tools

Quote:
Originally Posted by vbe
As you are talking of outlook - which is not UNIX...
I would try
Code:
cat hello.txt| $ux2dos |\mailx -s "Alert" ......

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

When i run the command with $ux2dos i get
Code:
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 ----------

Quote:
Originally Posted by mad man
Hi,

Have you tried like below? If not please try once, it might help.
Code:
echo "1\n" >>hello.txt
echo "2\n" >>hello.txt
echo "3\n" >>hello.txt

Thanks.
Does not Help !!

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

# 13  
Old 11-07-2016
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?
# 14  
Old 11-07-2016
Quote:
Originally Posted by RudiC
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
Quote:
echo "1\n"
Also dos2unix command is NOT found on my Linux

I then proceeded to do this but no success Smilie

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

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

Last edited by mohtashims; 11-07-2016 at 07:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Script to cat and dd last line!!! of each file

hi Guys, Am new to this awesome forum, and yea i need some help here asap thnx :) i have a directory with over 34000 text files, i need a script that will delete the last line of each of this file without me necessary opening the files. illustration:- file1 200 records file2 130 records... (5 Replies)
Discussion started by: eetang
5 Replies

2. Shell Programming and Scripting

for loop with whole line using cat

Hi all, I need to create loop script to read full line and append a variable to each line. cat file I need the output like below 10.0.0.1,136 1 24 048800 id N4 No_Light 10.0.0.1,137 1 25 048900 id N4 No_Light 10.0.0.1,140 1 28 048c00 id N4 No_Light 10.0.0.1,262 1 38 048e80... (13 Replies)
Discussion started by: ranjancom2000
13 Replies

3. Shell Programming and Scripting

Shell Scripting:Fetching content from each line with respect to pattern.

one.txt ONS.820.log:V 20Oct2010:GP ^ ^ ONS.123.log:V 21Oct2010:GP ^ ^ ONS.820.log:V 30Oct2010:GP ^ ^ want to make new file from existing one with addition. 20Oct2010 User KV001 has name tk003 with buffer- 338-1 21Oct2010 User KV003 has name tk002 with buffer- 338-2 30Oct2010 User KV002... (5 Replies)
Discussion started by: saluja.deepak
5 Replies

4. Shell Programming and Scripting

bash: cat multiple files together except first line?

Hopefully the title summarized what I need help with. I have multiple files that I would like to concatenate in bash. ie: cat file1 file2 file3 > bigfile except I do not want to include the first line from each file (). Any help? Thanks. (6 Replies)
Discussion started by: sanimfj
6 Replies

5. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

6. Shell Programming and Scripting

cat file1 read line-per-line then grep -A 15 lines down in fileb

STEP 1 # Set variable FILE=/tmp/mainfile SEARCHFILE =/tmp/searchfile # THIS IS THE MAIN FILE. cat /tmp/mainfile Interface Ethernet0/0 "outside", is up, line protocol is up Hardware is i82546GB rev03, BW 100 Mbps Full-Duplex(Full-duplex), 100 Mbps(100 Mbps) MAC address... (6 Replies)
Discussion started by: irongeekio
6 Replies

7. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

8. UNIX for Advanced & Expert Users

Amoung tar and gzip whiich unix command is more practical with respect to space manag

Hi All Can any body help me out. Amoung tar and gzip whiich unix command is more practical with respect to space management and file restoration. Eg if I use tar or gzip which will be more helpful to reduce the space and during the file restoration. Please help me out. regards... (3 Replies)
Discussion started by: manas6
3 Replies

9. Shell Programming and Scripting

Cat'ing a multiple line file to one line

I am writing a script that is running a loop on one file to obtain records from another file. Using egrep, I am finding matching records in file b, then outputing feilds of both into another file. **************************** filea=this.txt fileb=that.txt cat $filea | while read line do... (1 Reply)
Discussion started by: djsal
1 Replies

10. UNIX for Dummies Questions & Answers

using 'cat' to in 'while read line'

Hi, I'm having some trouble reading a file that was 'cat' through a while loop. Can anyone suggest alternatives? what i do is cat filename|grep *.stuff while read line do echo $line ... and other commands done The cat,grep line seems to work correctly, but the script hangs when i add in... (3 Replies)
Discussion started by: chugger06
3 Replies
Login or Register to Ask a Question