AS400 Qshell SED commands for Hex Editing

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.
OramcleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OramcleAuthor 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 started powershellCommented:
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.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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
OramcleAuthor 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 started powershellCommented:
>> 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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AS400

From novice to tech pro — start learning today.