sponsored links

Collapse

Announcement

Collapse
No announcement yet.

STRQSH and sed, tr commands

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

  • STRQSH and sed, tr commands

    I tried to use SED and TR to remove unwanted characters form file existing on IFS using STRQSH.

    I've found that sed doesn't work for regular expressions and for

    Examples
    1.
    Code:
    echo 'AB' | sed 's/[AB]/?/g'
    AB
    Result should be equal ='??'

    but

    Code:
    echo 'AB' | sed 's/A/?/g'
    ?B
    It is OK.

    2.
    SED change CRLF to LF if we use code like
    Code:
    sed -C 1250  's/[^[[:alnum:]\r\n]]/?/g' source.txt > result.txt
    if in source we have CRLF in result we found LF
    I could not find solution for such behaviour.

    3.
    SED ignore characters like xA0 in source file.
    Even if we use
    Code:
    sed -C 1250  's/[^[[:alnum:]\r\n]]/?/g' source.txt > result.txt
    where source includes x'A0' in result we still have x'A0'


    For SED from PHASE it is a little be better (pkt 1 works, 2,3 does not)

    For TR similar story.

    It seems be dissaster.

    Do you have any idea how I should solve above problems?




  • #2
    On my system in QShell:

    Click image for larger version

Name:	Qshell.png
Views:	53
Size:	9.8 KB
ID:	151495

    On my system with PASE (I assume you meant PASE rather than PHASE)

    Click image for larger version

Name:	pase.png
Views:	53
Size:	13.1 KB
ID:	151496

    This all looks correct to me.

    Comment


    • #3
      Of course PASE.

      I can't see the pictures attached to the answer: "Invalid File Specified"

      Comment


      • #4
        I don't know why you wouldn't be able to see the pictures. I can see them.

        The first one is a screenshot of a QShell session, it shows this:

        Code:
         > echo 'AB' | sed 's/[AB]/?/g'
           ??
        As you can see, it is resulting in ??. The second is a PASE session, showing the exact same results.

        I suspect you do not have your CCSID configured properly, and this is causing the [ and ] characters to be misinterpreted.

        Comment


        • #5
          Sed for PASE works OK but for QSHELL not.
          A different path and most likely different code is used for the PASE environment.
          What can misconfigured CCSID mean?
          Is it by any chance that the SED only operates for CCSID= 37?

          Comment


          • #6
            In your 5250 emulator (the program giving you the greenscreen terminal access to the iSeries), in its configuration, you can specify a CCSID. What CCSID is it set to, and what CCSID do your iSeries jobs/tables usually have?

            Comment


            • #7
              My 5250 session job data:
              Code:
              Device recovery action  . . . . . . . . . . . . . :   *ENDJOBNOLIST        
              Time slice end pool . . . . . . . . . . . . . . . :   *BASE                
              Print key format  . . . . . . . . . . . . . . . . :   *PRTHDR              
              Sort sequence . . . . . . . . . . . . . . . . . . :   *HEX                 
                Library . . . . . . . . . . . . . . . . . . . . :                        
              Language identifier . . . . . . . . . . . . . . . :   PLK                  
              Country or region identifier  . . . . . . . . . . :   PL                   
              Coded character set identifier  . . . . . . . . . :   870                  
              Default coded character set identifier  . . . . . :   870                  
              Character identifier control  . . . . . . . . . . :   *DEVD                
              Job message queue maximum size  . . . . . . . . . :   64                   
              Job message queue full action . . . . . . . . . . :   *PRTWRAP             
              Allow multiple threads  . . . . . . . . . . . . . :   *NO                  
              Auxiliary storage pool group  . . . . . . . . . . :   *NONE                
              Spooled file action . . . . . . . . . . . . . . . :   *KEEP    
              After QSH

              echo $QIBM_CCSID
              0

              DSPSYSVAL
              Code:
                                           Display System Value                  
              System value . . . . . :   QCCSID                                  
              Description  . . . . . :   Coded character set identifier          
              Coded character set                                                
                identifier . . . . . :   870        1-65535         

              Comment


              • #8
                https://www.ibm.com/support/knowledg...z/rzahznls.htm

                Comment


                • #9
                  After setting ENVVAR LANG = '/ QSYS.LIB / PL_PL.LOCALE' SED under QSH works correctly.
                  Scott thanks a lot

                  Comment


                  • #10
                    So, maybe someone use my result.
                    Below you can find a QSH command which replaces unwanted characters with spaces for data.txt file.

                    Result file is:
                    • Windows CRLF text file
                    • has the same CCSID as source file

                    Characters outside the set
                    "a-zA-Z0-9śŚćĆńŃęĘąĄłŁżŻźŹ|,._ -()\+"
                    are unwanted characters


                    Code:
                    cat data.txt | sed  's/[^a-zA-Z0-9śŚćĆńŃęĘąĄłŁżŻźŹ|,._ -()\+]/ /g' | awk '{printf "%s\r\n", $0}'   >   temp.out  && cp -p -t temp.out data.txt
                    Or if you use the same code for different files with different CCSID

                    Code:
                    rm -f temp.out
                    cat data.txt | sed  's/[^a-zA-Z0-9śŚćĆńŃęĘąĄłŁżŻźŹ|,._ -()\+]/ /g' | awk '{printf "%s\r\n", $0}'   >   temp.out  && cp -p -t temp.out data.txt

                    Comment

                    Working...
                    X