Converting LF to CRLF in IFS Files
October 17, 2007 Hey, Ted
Your best bet might be the CL-command route. The following sequence of commands converts file test-lf to test-crlf.
CRTPF QTEMP/SAVE RCDLEN(256) CPYFRMSTMF FROMSTMF('test-lf')
I looked for a Qshell solution and this is the only thing I could come up with.
touch -C 1252 test-crlf while read line; do echo "$liner"; done
The touch utility creates a file with CCSID 1252, which is the same format you get when you specify CPYTOSTMF … STMFCODPAG(*PCASCII). The while loop reads from standard input and writes to standard output. The echo command inside the while loop reads a line of the IFS file into a variable called line, then writes the line variable and carriage return to standard output.
I used the od utility to verify that each line of test-crlf was terminated with x’0D0A’.
od -tx test-crlf
Then I FTP’d both test-lf and test-crlf to my PC using a binary transfer. Notepad properly opened test-crlf, but not test-lf. However, there is one “feature” of this approach that may or may not be a problem: this method drops leading spaces from each line.
I talked to another Guru author, Bruce Guetzkow, who Googled and found the following sed command at a Web site called nixCraft.
sed 's/$'"/`echo r`/" test-lf >test-crlf
I tested this method, and it worked for me.
By the way, Google also tells me that many shops use a unix2dos utility. If it’s been ported to the System i, I’m not aware of it.