Inserting <carriage return> before <newline>:Title: SUMMARY: Inserting <carriage return> before <newline> the original question was: > some unix files crashes PC-applications because each line ends > with \n (newline), but should end with \r \n (carriage return > and newline). Has anybody a script (sed ?), that inserts \r > before \n ? Thanks for all the prompt responses. Here are the answers. ------------------------------------------------------------- Use ftp (asci-transfer-mode) ------------------------------------------------------------- this works fine!!! ------------------------------------------------------------- Use sed ------------------------------------------------------------- #/bin/csh -f sed -e 's/$/^M/' $1 > $2 ............................................................... Being that as it may: sed 's/$/^M/' file > file.Microsoft where you type the ^M as a control-V and a control-M will do the trick, just as sed 's/^M$//' file.Microsoft > file will reverse the process. ------------------------------------------------------------- Use other Unix-tools ------------------------------------------------------------- awk '{printf("%s\r\n", $0)}' filename.nl > filename.crnl cat file | awk '{printf $0 "\n\r"}' tr "\012" "\015" < infile > outfile <-- this does not work !! ------------------------------------------------------------- Use c-programs ------------------------------------------------------------- ------------------------------------------------------------- Use pearl (we dont have pearl) ------------------------------------------------------------- perl -pi.bak -e 's/\n/\r\n/' file #! /usr/bin/perl -wpi.bak s/$/\r/ ; #!/usr/local/bin/perl -pi~ s/\n/\r\n/o; #!/usr/local/bin/perl -pi~ s/\r//o; #!/usr/local/bin/perl # file name is c.pl # this has not been tested Werner! while (<>) { s/$/ /; print $_; } |