need help with recode command for CR/LF


 
Thread Tools Search this Thread
Operating Systems Linux SuSE need help with recode command for CR/LF
# 1  
Old 06-16-2009
need help with recode command for CR/LF

Not sure if this is a Linux issue or specific to SuSE Linux, but, in the infinite wisdom of the developers they decided to do away with the dos2unix and unix2dos commands which were very handy in handling the CR/LF issue between unix and dos/windows files.

More to the point I've created a tr command to strip CR's from dos/windows files in unix. However, the best/only way I can find to get the CR into unix files that I need to send to dos/windows is the recode command. However, every different conversion table that I've used to convert (pc, utf-8/CRLF, etc.) the file to get the CR LF pairs always puts the CR (0d) after the LF (0a) and not before. This poses a problem when I try to send this file in a mail message to Outlook.

The bottom line, the unix2dos command always put the CR (0d) before the LF (0a) whenever I ran it and I never had a problem sending these files to windows/outlook. However, when I do this using the recode command the Outlook mail message comes in with an attachment of .dat and doesn't look right when I open it.

I'm pretty sure this is an issue caused by the fact that the CR is being put AFTER the LF instead of before it on each line in the text file. I can take the same file, run it through the unix2dos command in a unix server I have and send it to my Outlook mail and the text comes in in the body of the email message and looks just fine. However, when I run the same file through recode and send it it comes in as an attachment to the email with a .dat extension.

Does anyone know of a conversion table that I can use in recode which will put the CR before the LF instead of after it?

Or, is there a way to accomplish this same thing using another unix/Linux command such as tr and/or sed?


Text File Data
-------------
This is line 1 of a test file.
This is line 2 of a test file.
This is line 3 of a test file.
This is line 4 of a test file.
This is line 5 of a test file.
This is line 6 of a test file.
This is line 7 of a test file.
This is line 8 of a test file.
This is line 9 of a test file.


Hex Dump of the above file (note the 0a LF's at the end of each line)
------------------------------------------------------------------
0000000 6854 7369 6920 2073 696c 656e 3120 6f20
0000020 2066 2061 6574 7473 6620 6c69 2e65 540a
0000040 6968 2073 7369 6c20 6e69 2065 2032 666f
0000060 6120 7420 7365 2074 6966 656c 0a2e 6854
0000100 7369 6920 2073 696c 656e 3320 6f20 2066
0000120 2061 6574 7473 6620 6c69 2e65 540a 6968
0000140 2073 7369 6c20 6e69 2065 2034 666f 6120
0000160 7420 7365 2074 6966 656c 0a2e 6854 7369
0000200 6920 2073 696c 656e 3520 6f20 2066 2061
0000220 6574 7473 6620 6c69 2e65 540a 6968 2073
0000240 7369 6c20 6e69 2065 2036 666f 6120 7420
0000260 7365 2074 6966 656c 0a2e 6854 7369 6920
0000300 2073 696c 656e 3720 6f20 2066 2061 6574
0000320 7473 6620 6c69 2e65 540a 6968 2073 7369
0000340 6c20 6e69 2065 2038 666f 6120 7420 7365
0000360 2074 6966 656c 0a2e 6854 7369 6920 2073
0000400 696c 656e 3920 6f20 2066 2061 6574 7473
0000420 6620 6c69 2e65 000a

I then run something similar to recode ..pc < recode.txt > recodecrlf.txt and it runs fine.

Hexdump of recodecrlf.txt
--------------------------
0000000 6854 7369 6920 2073 696c 656e 3120 6f20
0000020 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000040 6854 7369 6920 2073 696c 656e 3220 6f20
0000060 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000100 6854 7369 6920 2073 696c 656e 3320 6f20
0000120 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000140 6854 7369 6920 2073 696c 656e 3420 6f20
0000160 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000200 6854 7369 6920 2073 696c 656e 3520 6f20
0000220 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000240 6854 7369 6920 2073 696c 656e 3620 6f20
0000260 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000300 6854 7369 6920 2073 696c 656e 3720 6f20
0000320 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000340 6854 7369 6920 2073 696c 656e 3820 6f20
0000360 2066 2061 6574 7473 6620 6c69 2e65 0a0d
0000400 6854 7369 6920 2073 696c 656e 3920 6f20
0000420 2066 2061 6574 7473 6620 6c69 2e65 0a0d

Note that the Od follows the 0a instead of being before it


Hex dump of the same file run through a unix2dos command on a unix server
------------------------------------------------------------------------
0000000 5468 6973 2069 7320 6c69 6e65 2031 206f
0000020 6620 6120 7465 7374 2066 696c 652e 0d0a
0000040 5468 6973 2069 7320 6c69 6e65 2032 206f
0000060 6620 6120 7465 7374 2066 696c 652e 0d0a
0000100 5468 6973 2069 7320 6c69 6e65 2033 206f
0000120 6620 6120 7465 7374 2066 696c 652e 0d0a
0000140 5468 6973 2069 7320 6c69 6e65 2034 206f
0000160 6620 6120 7465 7374 2066 696c 652e 0d0a
0000200 5468 6973 2069 7320 6c69 6e65 2035 206f
0000220 6620 6120 7465 7374 2066 696c 652e 0d0a
0000240 5468 6973 2069 7320 6c69 6e65 2036 206f
0000260 6620 6120 7465 7374 2066 696c 652e 0d0a
0000300 5468 6973 2069 7320 6c69 6e65 2037 206f
0000320 6620 6120 7465 7374 2066 696c 652e 0d0a
0000340 5468 6973 2069 7320 6c69 6e65 2038 206f
0000360 6620 6120 7465 7374 2066 696c 652e 0d0a
0000400 5468 6973 2069 7320 6c69 6e65 2039 206f
0000420 6620 6120 7465 7374 2066 696c 652e 0d0a
# 2  
Old 06-16-2009
To convert the files you can use these commands:

Dos to Unix:

Code:
tr -d '\r' < dosfile > unixfile

Unix to Dos:

Code:
awk '{printf("%s\r\n",$0)}' unix_file > dosfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies

2. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

Recode alphabet into numbers

I have a genotype.bim file where it contains information about SNPs and genotype. As a hypothetical example, let's say genotype.bim snp1 ... A G snp2 ... G T snp3 ... G T snp4 ... G A ... snpN ... C G where first column identifies each SNP and 5th and 6th column has genotype... (3 Replies)
Discussion started by: johnkim0806
3 Replies

4. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

5. Shell Programming and Scripting

Recode A/T/G/C to 0/1 using a reference column

Hello, I have a large file that contains 114 total columns with over 6,000 rows and a header; the final 27 columns are coded in A/T/G/C. There is also a reference column coded A/T/C/G. e.g. OLD_file col1 col2 3 ref ... 27 28 29 30 ... 1 r 22 A ... G A G A ... 2 f 22 C ... T T C T ...... (2 Replies)
Discussion started by: peanuts48
2 Replies

6. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

7. Shell Programming and Scripting

Writing an algorithm to recode data points

I have a file that has been partially recoded so that data points that were formerly letter combinations are now -1, 0, or 1. I need to finish recoding the GG and CC data points. The file looks like this: ID 1 2 3 4 5 6 7 8 83845676 0 0 0 0 CC -1 CC CC 838469. -1 -1 1 GG CC 0 CC 1 83847041... (10 Replies)
Discussion started by: doobedoo
10 Replies

8. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

9. SuSE

inconsistent ls command display at the command prompt & running as a cron job

Sir, I using the following commands in a file (part of a bigger script): #!/bin/bash cd /opt/oracle/bin ls -lt | tail -1 | awk '{print $6}' >> /tmp/ramb.out If I run this from the command prompt the result is: 2007-05-16 if I run it as a cron job then... (5 Replies)
Discussion started by: rajranibl
5 Replies
Login or Register to Ask a Question