AS400 Qshell SED commands for Hex Editing

Oramcle
Oramcle used Ask the Experts™
on
Team,  I need to convert End of line Hex Character in a IFS file from  x0A to x0D0A . Please help me

Thank you In advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
VP Technology / Senior Consultant
Commented:
Couldn't figure out how to do it in the version of SED on IBM i PASE/QSH.  This worked in PASE using awk:

awk 'BEGIN{RS="^$";ORS="";getline;gsub("\n","\r&");print>ARGV[1]}' test.txt

If you need to automate, that's probably a good method.  For one time changes, I just use the freeware Windows program Notepad++, which has a built-in Windows/Unix line conversion tool:

Edit-EOL Conversion

- Gary

Author

Commented:
Thank you Gary,
qsh: 001-0019 Error found searching for command awk. No such path or directory

I cannot use awk in QSH.
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT

Commented:
Based on comment from here:
http://labs.geody.com/docs/magic_spells_linux_debian.php
(LF only, x0A; not CR/LF, x0D0A as in Windows)

you can use any one of the following commands at any Linux oriented platforms:
Initially content of the file in Linux(oriented) format:
$ /usr/bin/file  test.txt
test.txt: ASCII text
$ /usr/bin/od -t x1 test.txt
0000000 6f 6e 65 0a 74 77 6f 0a 74 68 72 65 65 0a
0000016

Open in new window

Using cygwin:
$ /bin/sed -i ':M;N;$!bM;s/\n/\r\n/g;' test.txt
$ /usr/bin/file  test.txt
test.txt: ASCII text, with CRLF, LF line terminators
$ /usr/bin/od -bc  test.txt
0000000 157 156 145 015 012 164 167 157 015 012 164 150 162 145 145 012
          o   n   e  \r  \n   t   w   o  \r  \n   t   h   r   e   e  \n
0000020
$ /usr/bin/od -bx  test.txt
0000000 157 156 145 015 012 164 167 157 015 012 164 150 162 145 145 012
           6e6f    0d65    740a    6f77    0a0d    6874    6572    0a65
0000020

Open in new window


Always use full path while using any command.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Gary PattersonVP Technology / Senior Consultant

Commented:
That's why I used PASE and not QShell.  You maybe able to run awk from Qshell using the full path:  /QOpenSys/usr/bin/awk

Author

Commented:
Thank you Gary... First of all Please accept my apologies for my delayed response. That worked.


Thank you Murugesan.
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT

Commented:
>> Thank you Murugesan.
echo This could have been giving at least 1 point | /usr/bin/wc
Gary PattersonVP Technology / Senior Consultant

Commented:
@Murugesan:  This wasn't a Linux or Cygwin question.  It was about the version of sed that is available in the IBM i (AS400) QShell environment - and mentioned in the headline.  Unfortunately, the sed command string that you provided is using extensions that aren't available in AS/400 Qshell, so that command won't work.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial