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 15171 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 ??

                        BillRichardson

                          Topic Starter


                          Intermediate

                          Thanked: 15
                          Re: Assigned for Awk in another Section
                          « Reply #15 on: December 26, 2009, 01:57:44 AM »
                          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 ??

                          Ghostdog74  or  BC  are welcome to offer their own Batch solution.
                          Bill Richardson

                          ghostdog74



                            Specialist

                            Thanked: 27
                            Re: Assigned for Awk in another Section
                            « Reply #16 on: December 26, 2009, 02:06:58 AM »
                            Ghostdog74  or  BC  are welcome to offer their own Batch solution.
                            you are not answering my question. I am very interested in your batch solution, but you make it so hard to decipher which ones your final solutions are. I am merely asking you to reorganise your batches into 1 batch file. If you have done it, then which one is the actual one? post number 1??

                            And for your information, i have already solved it with gawk. that's why i am interested when you post a batch solution to solve the same thing. If you are not going to reorganize your code, its fine with me. but you are not helping the others who see this post, that is your philosophy right?

                            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 #17 on: December 26, 2009, 02:11:02 AM »
                            Billrich is welcome to post a perl solution.

                            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 #18 on: December 26, 2009, 02:19:58 AM »
                              its from here

                              I could find no feedback from Eldorado, Topic Starter,  that the Awk (gawk ?) solution worked for Eldorado?


                              http://www.computerhope.com/forum/index.php/topic,97061.msg657265.html#msg657265

                              Topic: Record Manipulation with AWK  (Read 306 times)

                              Eldorado
                              Topic Starter
                              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 #19 on: December 26, 2009, 02:29:19 AM »
                              I could find no feedback from Eldorado, Topic Starter,  that the Awk (gawk ?) solution worked for Eldorado?

                              Sometimes when a solution works you never hear from the OP again. gawk stands for GNU Awk, (or, I imagine that's what it stands for).

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

                              ghostdog74



                                Specialist

                                Thanked: 27
                                Re: Assigned for Awk in another Section
                                « Reply #20 on: December 26, 2009, 02:31:59 AM »
                                I could find no feedback from Eldorado, Topic Starter,  that the Awk (gawk ?) solution worked for Eldorado
                                why does it matter? if it doesn't work, he will post back.
                                and don't shift the subject focus. you provide a batch solution, but its all over the place. Can you put them into one batch file.? that's all i am asking. You can treat me as a beginner in batch and i am asking you a favor now to combine them to make it easier for me and others. how about that ?

                                ghostdog74



                                  Specialist

                                  Thanked: 27
                                  Re: Assigned for Awk in another Section
                                  « Reply #21 on: December 26, 2009, 02:32:26 AM »
                                  gawk stands for GNU Awk, (or, I imagine that's what it stands for).
                                  yes.

                                  BillRichardson

                                    Topic Starter


                                    Intermediate

                                    Thanked: 15
                                    Re: Assigned for Awk in another Section
                                    « Reply #22 on: December 26, 2009, 02:33:20 AM »
                                    BillRichardson is welcome to post a perl solution.

                                    BC may offer his solution in "C", "Assembly", Perl or Machine Language . . .
                                    or any code at his command?

                                    I thought the Hope Board was designed for Batch?
                                    « Last Edit: December 27, 2009, 06:27:23 PM 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 #23 on: December 26, 2009, 02:45:01 AM »
                                    BC may offer his solution in "C", "Assembly", Pearl or Machine Language . . .
                                    or any code at his command?
                                    What the heck is Pearl? never heard of that language.

                                    Quote
                                    I thought the Hope Board was designed for Batch?
                                    Don't recall it ever saying that anywhere. the DOS board would, ideally, be for DOS batch files, you know, for DOS, not windows with command extensions. the only reason the DOS board is being used for Windows-based batches with command extensions is because otherwise they may as well remove it. maybe 1 in a thousand people are actually referring to a pure DOS batch. Because of that, and the fact that all versions of windows down to windows 98 natively support languages such as VBScript and jscript as the official scripting language of  the OS, any feasible solution is valid.

                                    If Ghostdog wants to post his solution in python, or awk, or what have you, then he's free to do so, especially when it solves the OP's problem. because, surprisingly, the OP most often doesn't really CARE what was used; as long as it solves the problem.
                                    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 #24 on: December 27, 2009, 11:05:45 AM »
                                      All users of Windows have access  to Batch files. They can create and/or use Batch files.

                                      Only one person in 1000 have access to Awk (gawk ) files.  Only one person in 3000 know how to use use Awk files.
                                      Bill Richardson

                                      Salmon Trout

                                      • Guest
                                      Re: Assigned for Awk in another Section
                                      « Reply #25 on: December 27, 2009, 12:18:07 PM »
                                      Only one person in 3000 know how to use use Awk files.

                                      And it isn't you, by the look of things!

                                      ghostdog74



                                        Specialist

                                        Thanked: 27
                                        Re: Assigned for Awk in another Section
                                        « Reply #26 on: December 27, 2009, 04:45:30 PM »
                                        All users of Windows have access  to Batch files. They can create and/or use Batch files.

                                        Only one person in 1000 have access to Awk (gawk ) files.  Only one person in 3000 know how to use use Awk files.
                                        i wish you could just stop babbling your nonsense and focus on what I, as a beginner in batch, wish you would do for me. Show me the final batch solution,  in one batch file.

                                        BillRichardson

                                          Topic Starter


                                          Intermediate

                                          Thanked: 15
                                          Re: Assigned for Awk in another Section
                                          « Reply #27 on: December 27, 2009, 06:22:50 PM »
                                          I look forward to your final result.

                                          See  awkbatfinal.bat in the opening post of this thread.

                                          There is only one main batch.  The main batch calls awkbat6.bat  and awkbat8.bat for lines 306 and 308.
                                          Bill Richardson

                                          eldorado



                                            Greenhorn

                                            Re: Assigned for Awk in another Section
                                            « Reply #28 on: December 27, 2009, 07:01:22 PM »
                                            Code: [Select]
                                            awk -F"|" '{
                                                a[$1]=a[$1] FS $2 FS $3
                                            }
                                            END{
                                                for(i in a){
                                                    print i,a[i]
                                                }
                                            }' file


                                            output
                                            Code: [Select]
                                            $ ./shell.sh
                                            301 |AF_ACC_BDL|774;|AF_WMG_BDL|6660;|AF_REP_BDL|4735;
                                            303 |AF_ACC_BDL|1360;
                                            304 |AF_ACC_BDL|5092;
                                            305 |AF_ACC_BDL|32384;
                                            306 |AF_ACC_BDL|80859;|AF_REP_BDL|80875;
                                            308 |AF_ACC_BDL|1418;|AF_WLH_BDL|78273;|AF_WSL_BDL|9990;|AF_WFL_BDL|9998;


                                            Hi ghostdog74,

                                            The solution you provided works perfectly. Thanks alot!  :)

                                            ghostdog74



                                              Specialist

                                              Thanked: 27
                                              Re: Assigned for Awk in another Section
                                              « Reply #29 on: December 27, 2009, 07:13:53 PM »
                                              See  awkbatfinal.bat in the first post of this thread.
                                              ok, i seen your code, but i wonder where are awkbat6.bat and awkbat8.bat ?? I have also run your code, but i have another question, if i have more data, like 309, 310, 311 etc...do i have to create awkbat09.bat , awkbat10.bat, awkbat11.bat etc as well??

                                              BillRichardson

                                                Topic Starter


                                                Intermediate

                                                Thanked: 15
                                                Re: Assigned for Awk in another Section
                                                « Reply #30 on: December 27, 2009, 07:29:28 PM »
                                                I see your code, but  wonder where are awkbat6.bat and awkbat8.bat ? I have also run your code, but I have another question, if I have more data, like 309, 310, 311 etc...do i have to create awkbat09.bat , awkbat10.bat, awkbat11.bat etc as well?


                                                I posted  awkbat8.bat  but you said you were not interested.

                                                Awkbat6.bat and awkbat8.bat is  generic code that will work for any line as it did for line 301.

                                                I saw no other input files from Eldorado,Topic Starter, other than what was used.

                                                If  Ghostdog 74  is really interested in a batch solution, please post the code you have written and we will work together. I see no need to continue if you don't offer to help.

                                                « Last Edit: December 27, 2009, 07:40:44 PM by BillRichardson »
                                                Bill Richardson

                                                Geek-9pm


                                                  Mastermind
                                                • Geek After Dark
                                                • Thanked: 1026
                                                  • Gekk9pm bnlog
                                                • Certifications: List
                                                • Computer: Specs
                                                • Experience: Expert
                                                • OS: Windows 10
                                                Re: Assigned for Awk in another Section
                                                « Reply #31 on: December 27, 2009, 07:33:17 PM »
                                                Quote
                                                Only one person in 1000 have access to Awk (gawk ) files

                                                HuH?   ???

                                                gawk for windows is available to everybody with internet.

                                                http://gnuwin32.sourceforge.net/packages/gawk.htm

                                                BillRichardson

                                                  Topic Starter


                                                  Intermediate

                                                  Thanked: 15
                                                  Re: Assigned for Awk in another Section
                                                  « Reply #32 on: December 27, 2009, 07:46:06 PM »
                                                  HuH?   ???

                                                  "gawk for windows is available to everybody with internet."

                                                  http://gnuwin32.sourceforge.net/packages/gawk.htm

                                                  My mistake.  I should have written that only one in 1000 ever  download or use awk (gawk).

                                                  Thanks for the download site.

                                                  http://gnuwin32.sourceforge.net/packages/gawk.htm

                                                  I will try again.
                                                  Bill Richardson

                                                  ghostdog74



                                                    Specialist

                                                    Thanked: 27
                                                    Re: Assigned for Awk in another Section
                                                    « Reply #33 on: December 27, 2009, 08:20:11 PM »
                                                    My mistake.  I should have written that only one in 1000 ever  download or use awk (gawk).
                                                    this is baseless and is fit for the rubbish bin.

                                                    ghostdog74



                                                      Specialist

                                                      Thanked: 27
                                                      Re: Assigned for Awk in another Section
                                                      « Reply #34 on: December 27, 2009, 08:38:07 PM »
                                                      I posted  awkbat8.bat  but you said you were not interested.
                                                      Awkbat6.bat and awkbat8.bat is  generic code that will work for any line as it did for line 301.
                                                      you keep saying there is awkbat8.bat, but where is it ??
                                                      and if they are generic, then why are there 2 versions of it awk6 and awk8?? if its generic, you should make it such that it works for all scenarios, no matter whether there are 309, 310 or 411 etc... why is there a need to call that many .bat files??

                                                      I am really a beginner in batch, and my gawk solution solves the problem for data like this
                                                      Code: [Select]
                                                      C:\test>more file
                                                      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;
                                                      309|AF_BLA_DDD|9999;
                                                      309|AF_BAL_DDE|99999;
                                                      309|AF_AAA_DDW|99959;
                                                      310|AF_XXX_AAA|1345;
                                                      310|AF_YYY_AAA|1235;
                                                      310|AF_ZZZ_BBB|1245;

                                                      C:\test>gawk -F"|" "{a[$1]=a[$1] FS $2 FS $3}END{for(i in a){ print i,a[i] } }" file
                                                      310 |AF_XXX_AAA|1345;|AF_YYY_AAA|1235;|AF_ZZZ_BBB|1245;
                                                      301 |AF_ACC_BDL|774;|AF_WMG_BDL|6660;|AF_REP_BDL|4735;
                                                      303 |AF_ACC_BDL|1360;
                                                      304 |AF_ACC_BDL|5092;
                                                      305 |AF_ACC_BDL|32384;
                                                      306 |AF_ACC_BDL|80859;|AF_REP_BDL|80875;
                                                      308 |AF_ACC_BDL|1418;|AF_WLH_BDL|78273;|AF_WSL_BDL|9990;|AF_WFL_BDL|9998;
                                                      309 |AF_BLA_DDD|9999;|AF_BAL_DDE|99999;|AF_AAA_DDW|99959;

                                                      notice the data now has 309, 310?? (and you can add more), but it will still solve it, without adding extra code. Now all i am asking you , since you started to do this in batch, is to do the same.  I do not want to create  extra batch files. I just want to do it in one batch file...is that ok ?? can you show me how please, in batch ?




                                                      BillRichardson

                                                        Topic Starter


                                                        Intermediate

                                                        Thanked: 15
                                                        Re: Assigned for Awk in another Section
                                                        « Reply #35 on: December 27, 2009, 10:10:34 PM »
                                                        GH,

                                                        I'm not an expert with batch.   I suspect someone by email has given you a better batch solution.  My solution works. It is not a good design nor good code.  You need someone with more skill than I can offer.  Good Luck.  We are getting nowhere.  You need a new start.  Send me your new batch program.

                                                        p.s. I got the gawk to work but not with the "all one line"  problem.
                                                        As good as you are:  start from scratch and write a new batch for this problem
                                                        « Last Edit: December 29, 2009, 11:24:51 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 #36 on: December 28, 2009, 07:47:04 AM »
                                                        I nominate this thread for *censored* of the year award.

                                                        In fact, I find it so *censored*-ey that I might even require it's URL as part of a shebang line for BCScript files, heh.

                                                        As good as you are:  start from scratch and write a new batch for this problem

                                                        Why? he has a working AWK solution.

                                                        Additionally I might wonder aloud why it is that you prefer batch over VBScript and JScript? your reasoning for awk is that it needs t be downloaded; but VBScript and JScript COME with ALL installations of windows since windows 98SE; any windows install past windows 95 (in fact, windows 95 has an OS update that I believe installs ActiveX Scripting engines such as VBS and JS) can use VBScript files. There is no reason to write a batch file if a working VBS or JS solution is provided, and works better. your statements that they are "easier to understand" are merely expressions of your own opinion and not actually decided through any real experience with people using VBS and batch files. batch files ALWAYS open a command prompt window; this, in and of itself, is enough to scare new users sometimes. VBScript, on the other hand, can be written to use WScript.exe and therefore use dialogs and Inputboxes rather then scary text mode Command prompt UI, so anybody who wouldn't understand VBScript would likely prefer the VBScript solution anyway, which brings up the point that the idea isn't always to educate the person seeking help as to the intricacies if the language, but rather to simply provide a solution; sometimes a batch solution, sometimes VBScript, but there is absolutely, positively, no reason to lean towards batch unless the OP has expressed a EXPLICIT interest in only batch-based solutions, and even in those cases a VBScript can be adapted to run from within a batch script anyway so the point is moot. If the OP then becomes interested in learning VBScript, they can be referred to a number of fine resources. I might even conclude that VBScript is EASIER for a new user to understand; BASIC statements roughly translate into plain english:

                                                        Code: [Select]
                                                        For Each Value In Collection
                                                            Print Value
                                                        Next Value

                                                        Is a *censored* of a lot easier to read then:

                                                        Code: [Select]
                                                        For /f %%P in (`type collection`) do echo %%P

                                                        Sure, they both have similarities, but the batch version is not exactly plain english, there are far too many semantics that would need to be explained, such as why there are percent signs, and of course why it is that when the OP uses the command at the command prompt you need only a single % sign. Batch being "simple" is a huge misperception by a large number of users, even the base language as used in Pure DOS is relatively confusing.

                                                        Only language I can think of being more "english-like" then BASIC  might be python; I don't have extensive experience but I will not argue the repeated point Ghostdog makes that it is easy t olearn for a beginner. It may not ALWAYS be the best choice (which I believe is where I and ghostdog disagree) but it certainly isn't a bad starting point for anybody.

                                                        Batch Is. Trust me, I know from experience that learning batch programming first can become a hurdle later on when learning a less domain-restricted programming language. When I first started with QBASIC after using batch, it took some time to realize that I wasn't writing commands, I was writing statements; my previous experience with batch was certainly only a minor hurdle, but a hurdle nonetheless. It's not necessarily a bad thing to learn batch; it's a bad thing to try to learn another language from the perspective of batch semantics, which I believe would hold true for nearly any programming language; they have different "spirits" to steal the term from Bruce McKinney, Author of "HardCore Visual Basic"; for example, the C "spirit" pretty much says the programmer is in control of everything; memory allocations, deallocations, everything must be done by them, and it is this "total control" concept that lends itself to streamlined, low-level C code. Visual Basic tries to hide a good number of things about windows programming from the programmer, sparing them the troubles of creating and maintaining window handles, sending and recieving window messages, etc. There is of course some allocation to be done, such as dimensioning variables (optional, actually, defaulting to the Single data type in Version 1 and to Variant In versions after, unless a Deftype statement is found in the declarations section of a module, in which case the default type for that module is the specified type), but once a variable goes out of scope, it is automatically destroyed. To some extend, C will do this; for static variables declared within procedures. However, pointers will NOT be automatically deallocated in C and this must be dealt with properly. The "spirit" if batch is the very essence of a "glue" language, that is, calling of a number of programs that were compiled in other languages (things like format, find, etc) in predefined orders, and with very specific and basic Control flow that was pretty much a spaghetti of gotos. It has evolved past this stage but it is still a glue language at it's core, and a glue language is limited in far too many ways to count and at the same time its powerful by the sum of the parts that is happens to glue together.

                                                        One of the things that batch can use as a glued piece is AWK, just as VBS code can be written to a file and executed from a batch, so to can AWK be executed from the command line, as an extension of batch.

                                                        Consider for a moment that almost every batch program calls into another program to do it's work, and all batch programs rely on cmd.exe to perform at the very least basic interpretation of the file; ther eis no denying that it has limitations, and one of these limitations can be found in text processing. warranted, it CAN do text processing, but it takes experience and patience to get it working; on the other hand, scripting languages like VBS have a number of string functions at their disposal, and their Date/time manipulation is simply not matched by any feasible batch solution.

                                                        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 #37 on: December 28, 2009, 03:44:03 PM »
                                                          I nominate this thread for *censored* of the year award.

                                                          BC  writes many lines of nonsense  and says nothing and offers no code of any kind as a solution.  What happened to the Perl Solution from BC?   Where is there a solution of any kind offered by BC?

                                                          Is Bc the dilettante of the Hope Board?

                                                          dil·et·tante (dl-tänt, dl-tänt, -tänt, -tnt, -tnt)
                                                          n. pl. dil·et·tantes also dil·et·tan·ti (-tänt, -tn-)
                                                          1. A dabbler in  a field of knowledge. See Synonyms at amateur.

                                                          Superficial; amateurish.
                                                          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 #38 on: December 28, 2009, 04:19:12 PM »
                                                          Learn to read, troll.
                                                          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 #39 on: December 28, 2009, 05:17:53 PM »
                                                            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 #40 on: December 29, 2009, 07:47:45 AM »
                                                            Where is BC's  code?

                                                            What code? I never promised any code.
                                                            I was trying to dereference Null Pointers before it was cool.

                                                            Salmon Trout

                                                            • Guest
                                                            Re: Assigned for Awk in another Section
                                                            « Reply #41 on: December 29, 2009, 08:56:34 AM »
                                                            Let's boycott him.