ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

When I run my grep from qsh command result is 0, but from qsh script its F025 hex

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • When I run my grep from qsh command result is 0, but from qsh script its F025 hex

    I'm using a simple grep to look for "ISA" in the first 3 characters of a line in a file. If I type it on the qsh command line it returns 0 if the value isn't there or 1 if its the first 3 characters of the first line

    grep -cF '^ISA' /home/Edi/IFSTextfile.txt

    But if I run this from a script, it produces hex F025 instead of a 0. If I redirect the output to a file I can look at the file and see this

    hex F0 is EBCDIC for 0 if my memory is correct, but I can't figure out a way to compare for that in my script

    if [[ $(grep -cF '^ISA' /home/Edi/IFSTextfile.txt) > 0 ]]
    then
    echo "Above IS an EDI file"
    else
    echo "Above Not an EDI file"
    fi

    I tried the PASE version of grep too.

    I'm at a loss how to get it to just send a 0 or 1 to the file. I am shocked I can't do something this simple without asking for help.

    Has anyone else hit this kind of problem? I think its code page or CCSID related, but don't know how to fix it. Thanks for any ideas...

  • #2
    Does this help?:



    Cheers,

    Emmanuel

    Comment


    • #3
      I took a minute to play with it, Bob, and I got it to work by leaving off the -F switch.

      Code:
      if [[ $(grep -c '^ISA' IFSTextfileISA.txt) > 0 ]] then . . .

      Comment


      • #4
        Originally posted by bobc_00001 View Post
        if I run this from a script, it produces hex F025 instead of a 0. . . . hex F0 is EBCDIC for 0 if my memory is correct. . .
        Your memory is correct, Bob. X'F0' is zero, and X'25' is line feed, which is the usual end-of-line marker for stream files. You were getting the zero after all.

        Comment


        • #5
          Thanks for the replies... Yes, actually, it was the context causing trouble for Qshell, and somehow that seemed to end up with EBCDIC results that then were difficult to work with.

          I found that the cause was that I had used an embedded if then else fi inside the main if then else fi structure. When I changed the code to use if then elif the code now works:

          # look for ISA to see if its an EDI file, at GS segment for PD to see if its POS file, std head program won't work due to lack of -c option, build tmp file with first 512 char of file for quick searching
          /QOpenSys/usr/bin/head -c 512 $file > /home/Edi/as2xrecc1.0.tmp
          # if bulk file rename bFILENAME, if POS file rename pFILENAME, else rename nFILENAME
          if [[ $(grep -cF '^ISA' /home/Edi/as2xrecc1.0.tmp) -eq 0 ]]
          then
          mv $targetfile b$targetfile
          # echo "$targetfile Above is a BULK file"
          elif [[ $(grep -cF 'GS*PD*' /home/Edi/as2xrecc1.0.tmp) -eq 0 ]]
          then
          mv $targetfile n$targetfile
          # echo "$targetfile Above Not a POS file"
          else
          mv $targetfile p$targetfile
          # echo "$targetfile Above IS a POS file"
          fi

          Comment

          Working...
          X