ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Modify delimeters in IFS

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

  • Modify delimeters in IFS

    I have a requirment to change delimeters in a file in the IFS from TAB to ~!. Is there a way anyone can think of today this? I was thinking of reading the IFS file using C runtime library functions and writing another file a new file, changin the TAB to ~! in each line I read.

    Other ideas are welcome.

  • #2
    Re: Modify delimeters in IFS

    Hi Gregwa50:

    1. open the file with wordpad or notepad
    2. in the first position enter a tab.
    3. Highlight the data just entered and cut
    4. select replace....paste the cut tab/enter ~! in the proper buckets
    5. replace all

    Best of Luck
    GLS

    < e d i t > .... replace 2 & 3 with copy a tab < e d i t >
    Last edited by GLS400; January 7, 2014, 03:21 PM.
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

    Comment


    • #3
      Re: Modify delimeters in IFS

      or use qsh

      cat /tmp/test.txt | tr -s '\t' '~!' > /tmp/test3.txt
      Last edited by dhanuxp; January 7, 2014, 11:46 AM.

      Comment


      • #4
        Re: Modify delimeters in IFS

        Originally posted by dhanuxp View Post
        or use qsh

        cat /tmp/test.txt | tr -s '\t' '~!' > /tmp/test3.txt
        Opsh sorry, It replace first character only.. I use the above command to replace TAB to # and worked well, but seems that 'tr' doesn't work with 2 or more characters in qsh but linux do...
        Last edited by dhanuxp; January 7, 2014, 11:52 AM.

        Comment


        • #5
          Re: Modify delimeters in IFS

          I noticed that if I edit the IFS file I can use the FIND (F16) or CHANGE (F17) to find/replace the delimeters by typing the appropriate command on the command line, e.g.
          Click image for larger version

Name:	IFS.PNG
Views:	1
Size:	2.5 KB
ID:	126720

          Problem is I have to press F17 for every field in the file. I'm hoping there is an *ALL option on the CHANGE command like there is in SEU. That way , I can change the all delimeters in the file with one shot

          Comment


          • #6
            Re: Modify delimeters in IFS

            Hi Gregwa50:

            Try this
            c ',' '!' all

            Best of Luck
            GLS
            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

            Comment


            • #7
              Re: Modify delimeters in IFS

              Are you sure you can using the single quotes? I would expect it to be more like:
              Code:
              c , ! all

              Comment


              • #8
                Re: Modify delimeters in IFS

                Scott:

                I just tested it ....It works both ways

                GLS
                The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

                Comment


                • #9
                  Re: Modify delimeters in IFS

                  That's good to know.

                  At any rate, this is an easy way to do it if you don't mind it being an interactive process. If you want to do it programmatically, you're better off using QShell or writing a program to do it.

                  Comment


                  • #10
                    Re: Modify delimeters in IFS

                    Looking back at this thread, I see that someone wanted to use 'tr' to do this -- but, at least historically, 'tr' is for replacing a single character with a single character. Often, you'll find more enhanced versions on OSes like Linux, but the "normal" tr could not replace more than one character at a time.

                    Instead, you'd typically use 'sed' for replacing whole strings, like this:
                    Code:
                    sed 's/,/~!/g' < inputfile > outputfile
                    So the expression 's/XXX/YYY/g' will replace all occurrences of XXX with YYY within a given line ("record") of the IFS file. You can put any strings you want there, and it'll find/replace them. Of course, this might be problematic if you had a comma inside the data itself (i.e. places where it's not just used as a delimiter).

                    Does that help at all?

                    Comment


                    • #11
                      Re: Modify delimeters in IFS

                      Originally posted by Scott Klement View Post
                      Looking back at this thread, I see that someone wanted to use 'tr' to do this -- but, at least historically, 'tr' is for replacing a single character with a single character. Often, you'll find more enhanced versions on OSes like Linux, but the "normal" tr could not replace more than one character at a time.

                      Instead, you'd typically use 'sed' for replacing whole strings, like this:
                      Code:
                      sed 's/,/~!/g' < inputfile > outputfile
                      So the expression 's/XXX/YYY/g' will replace all occurrences of XXX with YYY within a given line ("record") of the IFS file. You can put any strings you want there, and it'll find/replace them. Of course, this might be problematic if you had a comma inside the data itself (i.e. places where it's not just used as a delimiter).

                      Does that help at all?
                      Well, sort of. When on execute the command sed 's/,/~!/g' '/mystuff/Vendor.csv' '/mystuff/Venxx.csv'
                      I can see it making the changes and displaying them on the entry screen but at the end it says directory '/mystuff/Venxx.csv not found. What should I use for output file, does it already have to exist?

                      Comment


                      • #12
                        Re: Modify delimeters in IFS

                        Looks like you're missing the < and > characters that I had in my example?! The output file does not have to exist if it is a stream file, but it cannot be the same name as the input file (since it overwrites the output file, so if it's the same as the input file, it'll get wiped out before it can be processed.)

                        Comment


                        • #13
                          Re: Modify delimeters in IFS

                          Originally posted by Scott Klement View Post
                          Looks like you're missing the < and > characters that I had in my example?! The output file does not have to exist if it is a stream file, but it cannot be the same name as the input file (since it overwrites the output file, so if it's the same as the input file, it'll get wiped out before it can be processed.)
                          You're right, I added the < and >, works great.........awesome.

                          We have a client that wants the file we send them to be delimited with ~!. When they tell me there is an issue with the file, I like to be able to import it into Excel but Excel doesn't support more than one character for a delimeter. Using the command above, I can convert the ~! to , (or whatever) and review it in Excel.

                          Thanks a bunch

                          Comment

                          Working...
                          X