Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix2dos and extra lines

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hello All,

Could be I am in the wrong forum here so please bear with me.

I have a situation where a script is outputting two txt files.

Part of the script uses tr -d '\n' which I believe gets rid of all new line characters.This is neccessary so I will have to leave that in.

Later in the script, these two txt files are put together, and sent as an attachment using sendmail and uuencode.

Now to the problem.

Suppose the first txt file looks like this:

this is a txt file called bob

and the other one:

this is a txt file called billy

I do a cat file1 file2 > file3 and then a /usr/bin/unix2dos /path/to/file3 /path/to/file4 and then send of file 4 as an attachment.
I was hoping that the unix2dos utility would convert it to a format that windows can read.

On the receiving end (windows/dos) the file they receive looks like this:
this is a txt file called bobthis is a txt file called billy

which I don't want.

I am very new to unix, so I create a file called 'CR' which only contains an 'enter' character. Then I do

cat file1 CR file2 > file3 and then a /usr/bin/unix2dos /path/to/file3 /path/to/file4 and send this of.

Now the output looks like this:

this is a txt file called bob

this is a txt file called billy

which is much better. The only thing I can't figure out is how to get rid of that extra empty line between the two so the end result looks like this:

this is a txt file called bob
this is a txt file called billy

Has anybody got any ideas? And if you made this far, thank you for reading this newbie's long long question that probably has a simple simple solution.
 
To remove 'empty' lines :
sed '/^$/d' < yourfile > newfile
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Not sure if perhaps you wanted

unix2dos file1 > file2

From your explaination, the other thing I see is that your tr script deletes the final CR from your file1 and then when you cat them together, they appear on the same line already (before you convert them to dos).

Try man on your unix2dos, tr and cat for more detail. The tr looks like it is simply deleting CRs; the unix2dos is simply converting CRs to CR/LFs; cat basically appends one file to another.

Would your sequence be better served if you unix2dox your 2 files independently, and then cat them?

Hope this helps.

Hutch
 
Thanks all,

gives me a few pointers. I never really understood the sed command, I will take a look at the man pages...

Many thanks for your time.
 
BIS: learn regexp, you will become master in vi, sed, awk, perl, grep and all other...
mhutchis: unix2dos file1 > file2 is ok, but
unix2dos file1 file1 # make the same overwritting file1
:)
------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
...Well, ... since you started &quot;splitting Unix hairs&quot;, here ;-), I don't think the unix2dos command would attempt to overwrite the file without a redirection symbol between the two filenames, but yes, technically my statement is incorrect. Frankly, I was &quot;writing quickly&quot; to get the idea across.

Would you perhaps prefer?

unix2dos realfile1 > tempfile1
unix2dos realfile2 > tempfile2
cat tempfile1 tempfile2 > tempfile3

(reminder inserted here to remove messy tempfiles when done.)

Hutch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top