From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078611110616.tru64-unix-managers.marc@archive.invalid> From: George Gallen Date: Wed, 23 Apr 1997 10:48:00 +0000 To: tru64-unix-managers Subject: SUMMARY: Can unix2dos be changed to not change the original file? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078611110616 There were a multitude of suggestions, It seems most stated to stop unix2dos from changing the original file, to run dos2unix on it, I didn't like this idea after I found out a little problem with unix2dos, if you attempt to run unix2dos on a file that is NOT in your current directory it DELETES the original file and instead writes to the current directory a temp file of it's own (but not named anything like the original) so you will need to do either... 1. rename & copy the temp file back to it's appropriate resting place 2. cd to the appropriate directory BEFORE running unix2dos. I assume dos2unix does the same thing. George Gallen ggallen@slackinc.com Solution #1 - Copy original file to a temp file, unix2dos it then delete the temp file. -------------------------------------------------------------------------- -------------------------------------- Solution #2 - use a small C program as a filter (from jgmicon@sandia.gov) Here is a C program that does what you want. int main () { char buffer[1]; while (read(0,buffer,1)) { if (*buffer == '\n') write(1,"\r",1); write(1,buffer,1); } } here's how you compile it: cc -O -o filter filter.c here's how you use it: cat origfile | filter | uuencode OUTPUTNAME | mailx -s xxx user@domain -------------------------------------------------------------------------- -------------------------------------- Solution#3 - Get the Alias to work and use sed. Solution A Have you tried putting the appropriate sed commands into a file and using the file with sed -f? That should work. (and yes it did work) Tom Dr. Thomas P. Blinn, UNIX Software Group, Digital Equipment Corporation 110 Spit Brook Road, MS ZKO3-2/U20 Nashua, New Hampshire 03062-2698 Technology Partnership Engineering Phone: (603) 881-0646 Internet: tpb@zk3.dec.com Digital's Easynet: alpha::tpb ACM Member: tpblinn@acm.org PC@Home: tom@felines.mv.net Solution B Try using a backslash escape on the $ (i.e. sed -e 's/\$/^M/').--- Andy Wagliardo wagliardo@apo.saic.com (this stopped the error on sourcing...but it still needed one more step - see below) ----------------------------------- Try (in a file) alias unix2dos '/usr/bin/sed -e ''''s/\$/^V^M/''''' Explanation: The outmost quotes have to enclose the whole alias, therefore the innermost quotes must be quoted so that they not will be interpreted as part of the alias. The reasons why there are two pairs of four quotes are that if the alias is put in a file, the shell will need one pair when parsing the file and the 'exec' (or 'source', if you like) the other. If you do the alias from the commandline you will then need only one pair of quotes, ie alias unix2dos '/usr/bin/sed -e ''s/\$/^V^M/''' The backslash in front of the $ is to prevent the shell from interpreting it as part of a variable. ****************************************************************** * Knut Helleb? | DAMN GOOD COFFEE !! * * Norsk Hydro a.s | (and hot too) * * Phone: +47 55 996870, Fax: +47 55 996342 | * * Cellular Phone: +47 93092402 | * * E-mail: Knut.Hellebo@nho.hydro.com | Dale Cooper, FBI * ****************************************************************** -------------------------------------------------------------------------- -------------------------------------- Solution#4 - Try using 'dd' to make the conversion. I didn't see anything in dd that jumped right out at me, but I wouldn't doubt it's possible. -------------------------------------------------------------------------- --------------------------------------- Original Post I have tried multiple ways using redirection and piping, but to no avail, I have also tried using MTOOLS mcopy (with the t option) to create a temp file, but it seems you cant use mcopy to go unix->unix. What am I trying to do? I want to email a file as an attachment (ie). and have the lf converted to lf/cr (the file will be read on an MSDOS machine). Ultimatly I want to be able to do something like.... unix2dos origfile | uuencode OUTPUTNAME | mailx -s xxx user@domain I tried using sed (which worked excellent from the command line) but..... I am attempting to use this from a shell from a database program, which I cannot embedd ^V^M for sed to do its stuff. I tried adding the sed command as an alias to my .cshrc file, but I can't get to function correctly (this way instead of embedding ^V^M I could use a preset alias) : alias unix2dos "/usr/bin/sed -e 's/$/^M/'" (the ^M is typed in as ^V^M) (which gives "varible syntax" when sourced). SO....... What am I doing wrong with my alias.........or How do you get unix2dos to not change original file.......or Can Mtools be used (with t option) to do lf->cr/lf while doing unix->unix. Not too tough I hope. George Gallen ggallen@slackinc.com