Converting LF to CRLF in IFS Files
October 17, 2007 Hey, Ted
I had a situation where I wanted to change the end-of-line character from linefeed to carriage-return/linefeed to make a JavaScript file on the Integrated File System more readable in Notepad. I stumbled upon EDIT FILE (EDTF), F15, option 5. Then, after a little searching, I found your articles. Talk about reinventing the wheel! I was surprised that changing end-of-line characters was not part of the CHANGE ATTRIBUTE (CHGATR) command (or some other command). Is there any chance you could share a Qshell solution that converts LF to CRLF? I love using Qshell when I can, but sometimes it really stumps me. –Bruce 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. –Ted RELATED STORIES EDTF and End-of-Line Delimiters EDTF and End-of-Line Delimiters, Take Two Stream Files and End-of-Line Delimiters, Take Three
|