Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Assigned for Awk in another Section  (Read 15208 times)

0 Members and 1 Guest are viewing this topic.

BillRichardson

    Topic Starter


    Intermediate

    Thanked: 15
    Assigned for Awk in another Section
    « on: December 24, 2009, 08:38:10 PM »
    "Record Manipulation with AWK1 post - 1 author - Last post: yesterday
    Record Manipulation with AWK. ... I have tried with awk but to no avail. My code: awk ' { FS = "|" matchcnt = 0 if ( $1 != prev ) ...
    www.computerhope.com/forum/index.php?topic=97061.0
    "


    C:\batch>type awkbatfinal.bat

    Code: [Select]
    @echo off
    setLocal EnableDelayedExpansion
    set result=
    echo. > outinfile.txt
    for /f "tokens=1-3 delims=|" %%a in (awkinfile.txt) do (
    set var1=301
    set var2=%%a
    echo var1=!var1!
    if !var2!==!var1! (
    echo var2 is the same var1

    set line=%%b%%c
    set result=!result!!line!
    echo line=!line!
    echo result=!result!



    ) else (
    echo var2 = !var2!
    goto  end
    )
    )
    :end
    echo Input
    for /f "delims=" %%a in (awkinfile.txt) do (
    echo %%a
    )

    echo !var1!^|!result!  >> outinfile.txt
    findstr "303" awkinfile.txt  >>  outinfile.txt
    findstr "304" awkinfile.txt  >>  outinfile.txt
    findstr "305" awkinfile.txt  >>  outinfile.txt
    echo Output
    type outinfile.txt

    @echo  off

    call awkbat6.bat

    call awkbat8.bat

    echo END

    OUTPUT:

    C:\batch> awkbatfinal.bat
    var1=301
    var2 is the same var1
    line=AF_ACC_BDL774;
    result=AF_ACC_BDL774;
    var1=301
    var2 is the same var1
    line=AF_WMG_BDL6660;
    result=AF_ACC_BDL774;AF_WMG_BDL6660;
    var1=301
    var2 is the same var1
    line=AF_REP_BDL4735;
    result=AF_ACC_BDL774;AF_WMG_BDL6660;AF_REP_BDL4735;
    var1=301
    var2 = 303
    Input
    301|AF_ACC_BDL|774;
    301|AF_WMG_BDL|6660;
    301|AF_REP_BDL|4735;
    303|AF_ACC_BDL|1360;
    304|AF_ACC_BDL|5092;
    305|AF_ACC_BDL|32384;
    306|AF_ACC_BDL|80859;
    306|AF_REP_BDL|80875;
    308|AF_ACC_BDL|1418;
    308|AF_WLH_BDL|78273;
    308|AF_WSL_BDL|9990;
    308|AF_WFL_BDL|9998;
    Output

    301|AF_ACC_BDL774;AF_WMG_BDL6660;AF_REP_BDL4735;
    303|AF_ACC_BDL|1360;
    304|AF_ACC_BDL|5092;
    305|AF_ACC_BDL|32384;
    var1=306
    var2 is the same var1
    line=AF_ACC_BDL80859;
    result=AF_ACC_BDL80859;
    var1=306
    var2 is the same var1
    line=AF_REP_BDL80875;
    result=AF_ACC_BDL80859;AF_REP_BDL80875;
    var1=306
    var2 = 307
    Input
    301|AF_ACC_BDL|774;
    301|AF_WMG_BDL|6660;
    301|AF_REP_BDL|4735;
    303|AF_ACC_BDL|1360;
    304|AF_ACC_BDL|5092;
    305|AF_ACC_BDL|32384;
    306|AF_ACC_BDL|80859;
    306|AF_REP_BDL|80875;
    308|AF_ACC_BDL|1418;
    308|AF_WLH_BDL|78273;
    308|AF_WSL_BDL|9990;
    308|AF_WFL_BDL|9998;
    Output

    301|AF_ACC_BDL774;AF_WMG_BDL6660;AF_REP_BDL4735;
    303|AF_ACC_BDL|1360;
    304|AF_ACC_BDL|5092;
    305|AF_ACC_BDL|32384;
    306|AF_ACC_BDL80859;AF_REP_BDL80875;
    line=AF_ACC_BDL1418;
    result=AF_ACC_BDL1418;
    line=AF_WLH_BDL78273;
    result=AF_ACC_BDL1418;AF_WLH_BDL78273;
    line=AF_WSL_BDL9990;
    result=AF_ACC_BDL1418;AF_WLH_BDL78273;AF_WSL_BDL9990;
    line=AF_WFL_BDL9998;
    result=AF_ACC_BDL1418;AF_WLH_BDL78273;AF_WSL_BDL9990;AF_WFL_BDL9998;
    var2 = 309
    Input
    301|AF_ACC_BDL|774;
    301|AF_WMG_BDL|6660;
    301|AF_REP_BDL|4735;
    303|AF_ACC_BDL|1360;
    304|AF_ACC_BDL|5092;
    305|AF_ACC_BDL|32384;
    306|AF_ACC_BDL|80859;
    306|AF_REP_BDL|80875;
    308|AF_ACC_BDL|1418;
    308|AF_WLH_BDL|78273;
    308|AF_WSL_BDL|9990;
    308|AF_WFL_BDL|9998;
    Output

    301|AF_ACC_BDL774;AF_WMG_BDL6660;AF_REP_BDL4735;
    303|AF_ACC_BDL|1360;
    304|AF_ACC_BDL|5092;
    305|AF_ACC_BDL|32384;
    306|AF_ACC_BDL80859;AF_REP_BDL80875;
    308|AF_ACC_BDL1418;AF_WLH_BDL78273;AF_WSL_BDL9990;AF_WFL_BDL9998;
    END
    C:\batch>
    « Last Edit: December 27, 2009, 06:08:05 PM by BillRichardson »
    Bill Richardson

    ghostdog74



      Specialist

      Thanked: 27
      Re: Assigned for Awk in another Section
      « Reply #1 on: December 24, 2009, 09:15:53 PM »
      i look forward to your final result

      BillRichardson

        Topic Starter


        Intermediate

        Thanked: 15
        Re: Assigned for Awk in another Section
        « Reply #2 on: December 25, 2009, 09:29:58 AM »
        The following awk code by Ghostdog74**  does not work on my machine. I have an old MKS  version of awk:

        **
        "Record Manipulation with AWK1 post - 1 author - Last post: yesterday
        Record Manipulation with AWK. ... I have tried with awk but to no avail. My code: awk ' { FS = "|" matchcnt = 0 if ( $1 != prev ) ...
        www.computerhope.com/forum/index.php?topic=97061.0
         "

        awk -F"|" '{
            a[$1]=a[$1] FS $2 FS $3
        }
        END{
            for(i in a){
                print i,a
            }
        }' file

        The error message on my machine: "Exec Error:  Glob Error."

        May we see the output from the Ghostdog74  machine?

        Thanks for the Help
        « Last Edit: December 25, 2009, 11:37:41 AM by BillRichardson »
        Bill Richardson

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Assigned for Awk in another Section
        « Reply #3 on: December 25, 2009, 09:34:31 AM »
        The following awk code by Ghostdog74 [1]

        Citation needed
        I was trying to dereference Null Pointers before it was cool.

        ghostdog74



          Specialist

          Thanked: 27
          Re: Assigned for Awk in another Section
          « Reply #4 on: December 25, 2009, 06:03:38 PM »
          The following awk code by Ghostdog74**  does not work on my machine. I have an old MKS  version of awk:
          why use mks ?? I use gawk from GNU. also show the whole code have.
          as requested, i have also posted my output at the original thread.

          ghostdog74



            Specialist

            Thanked: 27
            Re: Assigned for Awk in another Section
            « Reply #5 on: December 25, 2009, 06:06:26 PM »

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Assigned for Awk in another Section
            « Reply #6 on: December 25, 2009, 06:45:30 PM »
            heh, I missed the "old MKS version" thing.

            like seriously, what are you supposed to do? Rewrite it so that people who don't care what version they have, or more precisely, that purposely download older versions to attempt to break the script will be satisfied?

            Should I rewrite all my Visual Basic programs so they work in VB 1.0, just in case I release my code and somebody has VB 1.0 from 1983? yeah, I don't see THAT happening either.

            My interpretation is that unless otherwise specified one should try the LATEST version of the tool, especially when they are fully aware of the age of the interpreter they are using. and to actually suggest the fault is the original author's is preposterous.

            I was trying to dereference Null Pointers before it was cool.

            BillRichardson

              Topic Starter


              Intermediate

              Thanked: 15
              Re: Assigned for Awk in another Section
              « Reply #7 on: December 25, 2009, 07:01:29 PM »

              "And to actually suggest the fault is the original author's is preposterous."

              Has BC ever used Awk?    I have tried to download the gawk  that ghostdog74 suggested  but have not been able to.  MKS is a respected company and many people use their products.

              I did not suggest the fault lies with Ghostdog74 or the original poster.  I'm not able to get the awk  program to run and I'm not sure what I'm doing wrong.  Many times code here at this site is not tested. 

              p.s.  The batch solution above  did work and output was provided,
              Bill Richardson

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: Assigned for Awk in another Section
              « Reply #8 on: December 25, 2009, 07:15:19 PM »
              Has BC ever used Awk?    I have tried to download the gawk  that ghostdog74 suggested  but have not been able to.  MKS is a respected company and many people use their products.

              I did not suggest the fault lies with Ghostdog74 or the original poster.  I'm not able to get the awk  program to run and I'm not sure what I'm doing wrong.  Many times code here at this site is not tested. 

              p.s.  The batch solution above  did work and output was provided,

              I never said anything about MKS. It's PERFECTLY CLEAR that you INTENTIONALLY downloaded an OLD version just to try to make the provided AWK script fail. Output doesn't prove a *censored* thing. Actually TESTING the program DOES, and while getting the output is one way of testing, there is no reason to clutter up posts with pages upon pages of your useless DIR commands that have absolutely no relevance to the question.

              I was trying to dereference Null Pointers before it was cool.

              ghostdog74



                Specialist

                Thanked: 27
                Re: Assigned for Awk in another Section
                « Reply #9 on: December 25, 2009, 07:54:02 PM »
                Has BC ever used Awk?    I have tried to download the gawk  that ghostdog74 suggested  but have not been able to.  MKS is a respected company and many people use their products.
                what is your difficulty in downloading gawk? also most of the frequently used tools that you can see in *nix are  ported to windows through GNU and its free...mks is a commercial company. Why buy when there is free ?

                Quote
                I did not suggest the fault lies with Ghostdog74 or the original poster.  I'm not able to get the awk  program to run and I'm not sure what I'm doing wrong.  Many times code here at this site is not tested. 
                like i said, post what went wrong, and your code that went wrong... i (we) can trouble shoot for you.

                Quote
                p.s.  The batch solution above  did work and output was provided,
                ok so the last time you did mention 306/308? is not completed right? so its complete now?? which one? please refine your output and remove all those unnecessary ones...its still the same "hard to decipher what is what" format.


                ps
                Quote from: BillRichardson
                Code: [Select]
                awk ' { FS = "|" matchcnt = 0 if ( $1 != prev )..
                at first glance, this is wrong already.

                BillRichardson

                  Topic Starter


                  Intermediate

                  Thanked: 15
                  Re: Assigned for Awk in another Section
                  « Reply #10 on: December 25, 2009, 08:26:36 PM »
                  I look forward to your final result

                  See  awkbatfinal.bat in the first post of this thread.
                  « Last Edit: December 27, 2009, 06:32:24 PM by BillRichardson »
                  Bill Richardson

                  ghostdog74



                    Specialist

                    Thanked: 27
                    Re: Assigned for Awk in another Section
                    « Reply #11 on: December 25, 2009, 09:06:52 PM »
                    The following batch file puts  all of the 308 lines on one line as requested by the original poster.  All other lines from the original poster are handled with a similar method.
                    i am only interested in the full solution.

                    BC_Programmer


                      Mastermind
                    • Typing is no substitute for thinking.
                    • Thanked: 1140
                      • Yes
                      • Yes
                      • BC-Programming.com
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Beginner
                    • OS: Windows 11
                    Re: Assigned for Awk in another Section
                    « Reply #12 on: December 25, 2009, 09:13:44 PM »
                    Oh, I see what this post is. Just BillRich performing his ol' complaints about how everyone ignores his DIR listings.
                    I was trying to dereference Null Pointers before it was cool.

                    BillRichardson

                      Topic Starter


                      Intermediate

                      Thanked: 15
                      Re: Assigned for Awk in another Section
                      « Reply #13 on: December 26, 2009, 01:43:35 AM »
                      Oh, I see what this post is. Just  complaints about how everyone ignores  DIR listings.

                      Reply #10 does not use the Dir command.  Casper, the full solution has already been given with the topic starter.

                      Will BC offer a batch or an Awk solution?  Thanks BC for your kind and helpful comments.  All members look forward to BC's  batch solution.
                      Bill Richardson

                      ghostdog74



                        Specialist

                        Thanked: 27
                        Re: Assigned for Awk in another Section
                        « Reply #14 on: December 26, 2009, 01:50:56 AM »
                        The full solution has already been given.
                        so which post number is it ? all i can see is you have a lot of disparate batch files like awkbat6, awkbat8 etc ...can you combine the full solution into 1 batch file ??