sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Replace character in a IFS file

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

  • Replace character in a IFS file

    Hi all

    I'm looking an example (possible in RPG) that replace some character with
    other (that i want) inside an Ifs file

    Thanks in advance

    Gio

  • #2
    You can use java QSHELL and the STREAM EDITOR to do this very easily (which you invoke from QCMDEXC if you really wanted to embed it in an RPG or RPGLE program).

    For example - STRQSH CMD('sed "s/beer/sausages" /littenn/test.txt > /littenn/result.txt') will replace the word "beer" with the word "sausages" in the IFS file '/littenn/result.txt' (or optionally pipe the results to a brand new file called "/littenn/result.txt")

    predictably positive, permanently punctilious, purposely proactive, potentially priceless, primarily professional : projex

    Comment


    • zukes1966
      zukes1966 commented
      Editing a comment
      "sed" called from strqsh DOES NOT work for regular expressions just try:
      echo 'AB' | sed 's/[AB]/?/g'
      result
      AB
      but
      echo 'AB' | sed 's/A/?/g'
      result:
      ?B
      Do not waste time on sed.

  • #3
    Quick and easy solution with embedded SQL:

    Code:
    DCL-S  FromIFSFile     SQLTYPE(CLOB_File);                                
    DCL-S  ToIFSFile       SQLTYPE(CLOB_File);
    /--------------------------------------------------------------------------------------------------------
      FromIFSFile_Name = '/home/YourDir/MyIFSFile.txt';                      
      FromIFSFile_NL   = %Len(%Trim(FromIFSFile_Name));                      
      FromIFSFile_FO   = SQFRD;                              //Read Only    
    
      ToIFSFile_Name = '/home/YourDir/MyIFSFile.txt';                        
      ToIFSFile_NL   = %Len(%Trim(ToIFSFile_Name));                          
      ToIFSFile_FO   = SQFOVR;                           //Replace          
    
      Exec SQL  Set :ToIFSFile = Replace(:FromIFSFile,
                                        'FromValue', 'ToWhatever');            
      //Handle SQLCODE  or SQLState                                                  
    
    *InLR       = *On;
    Birgitta
    Last edited by B.Hauser; January 16th, 2019, 12:19 AM.

    Comment


    • zukes1966
      zukes1966 commented
      Editing a comment
      The Birigida's answer simply does not work.
      Why?

      Program produces sqlCode = -332 and tells that: " ... conversion between CCSID (for instance) 1208 and CCSID 65535 not valid "

      1208 is taken by SQL as code page for FromIFSFile but for ToIFSFile it does not work.
      Even ToIFSFile exists.

      I tried

      DCL-S ToIFSFile SQLTYPE(CLOB_File) CCSID 1250;

      but it does not help.

      So, do you have any other smart idea to change base program for working?

  • #4
    Originally posted by NickLitten View Post
    You can use java QSHELL and the STREAM EDITOR to do this very easily (which you invoke from QCMDEXC if you really wanted to embed it in an RPG or RPGLE program).

    For example - STRQSH CMD('sed "s/beer/sausages" /littenn/test.txt > /littenn/result.txt') will replace the word "beer" with the word "sausages" in the IFS file '/littenn/result.txt' (or optionally pipe the results to a brand new file called "/littenn/result.txt")

    I Birigitta and Nick
    thanks for you reply
    another question: is it possible replace in a IFS file all character less than blank
    for an rpg string a would do in thsi way

    Code:
    D from            C                   X'000102030405060708090A0B0C0D0E-  
         D                                     101112131415161718191A1B1C1D1E1F-  
         D                                     202122232425262728292A2B2C2D2E2F-  
         D                                     303132333435363738393A3B3C3D3E3F'  
         D to              c                   '                               -  
         D      
             fld    = %xlate(from:to:fld);

    Comment

    Working...
    X