Why do this awk script print the original file too?calling awk script from C++ stops at “bozo :wait_for”awk - counting content of filesawk print column $3 if $2==a specific value?Linux shell scripting - Simple awk script issuePrint out all remaining variables in awkAwk not working inside bash scriptAWK doesn't work in Bash Scriptprint lines with blank in file using awkUNIX AWK script - memory exhaustedWhy is using variables in awk scripts breaking the counter?

How to save PDFs from web for offline reading on an iPad?

What is a realistic time needed to get a properly trained army?

Can I disable a battery powered device by reversing half of its batteries?

Do Milankovitch Cycles fully explain climate change?

Honourable versus Right Honourable Members

Are CO₂ tire cartridges reusable for multiple tires?

Is there a standard terminology for female equivalents of terms such as 'Kingdom' and if so, what are the most common terms?

„nichts wie raus hier“ - explanation based on the literal meaning?

How to add a theme preprocess function for published state?

My employer wants me to do a work of 6 months in just 2 months

What is Japanese Language Stack Exchange called in Japanese?

How to split a string by the third .(dot) delimiter

What does "synoptic" mean in avionics?

Evidence that matrix multiplication cannot be done in O(n^2 poly(log(n))) time

Why should I always enable compiler warnings?

Kingdom Map and Travel Pace

How to find a missing person abroad

How could a imperial dynasty keep a loose collection of pirates, raiders, etc unified?

Is the union of a chain of elementary embeddings elementary?

Do any aircraft carry boats?

Random point on a sphere

Exact Brexit date and consequences

Are there any instances of members of different Hogwarts houses coupling up and marrying each other?

How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?



Why do this awk script print the original file too?


calling awk script from C++ stops at “bozo :wait_for”awk - counting content of filesawk print column $3 if $2==a specific value?Linux shell scripting - Simple awk script issuePrint out all remaining variables in awkAwk not working inside bash scriptAWK doesn't work in Bash Scriptprint lines with blank in file using awkUNIX AWK script - memory exhaustedWhy is using variables in awk scripts breaking the counter?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have following script:



ascript2.awk



#!/usr/bin/awk -f
BEGIN FS=":"
a[$1]=a[$1] ";" $2 " : " $3
END
for (x in a) print x,a[x]


When I let it run, it prints also the original intput file. Why?
When I make a bash script like this it works fine:



merge



#!/bin/bash
awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1


Input:



Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3


Outputs:



$ ./merge t.txt
Money ; 9:test3
Affe ; 3:test 5:test2

$ ./ascript2.awk t.txt
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Money ; 9 : test3
Affe ; 3 : test; 5 : test2









share|improve this question
































    1















    I have following script:



    ascript2.awk



    #!/usr/bin/awk -f
    BEGIN FS=":"
    a[$1]=a[$1] ";" $2 " : " $3
    END
    for (x in a) print x,a[x]


    When I let it run, it prints also the original intput file. Why?
    When I make a bash script like this it works fine:



    merge



    #!/bin/bash
    awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1


    Input:



    Affe : 3 : test
    Affe : 5 : test2
    Money : 9 : test3


    Outputs:



    $ ./merge t.txt
    Money ; 9:test3
    Affe ; 3:test 5:test2

    $ ./ascript2.awk t.txt
    Affe : 3 : test
    Affe : 5 : test2
    Money : 9 : test3
    Money ; 9 : test3
    Affe ; 3 : test; 5 : test2









    share|improve this question




























      1












      1








      1








      I have following script:



      ascript2.awk



      #!/usr/bin/awk -f
      BEGIN FS=":"
      a[$1]=a[$1] ";" $2 " : " $3
      END
      for (x in a) print x,a[x]


      When I let it run, it prints also the original intput file. Why?
      When I make a bash script like this it works fine:



      merge



      #!/bin/bash
      awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1


      Input:



      Affe : 3 : test
      Affe : 5 : test2
      Money : 9 : test3


      Outputs:



      $ ./merge t.txt
      Money ; 9:test3
      Affe ; 3:test 5:test2

      $ ./ascript2.awk t.txt
      Affe : 3 : test
      Affe : 5 : test2
      Money : 9 : test3
      Money ; 9 : test3
      Affe ; 3 : test; 5 : test2









      share|improve this question
















      I have following script:



      ascript2.awk



      #!/usr/bin/awk -f
      BEGIN FS=":"
      a[$1]=a[$1] ";" $2 " : " $3
      END
      for (x in a) print x,a[x]


      When I let it run, it prints also the original intput file. Why?
      When I make a bash script like this it works fine:



      merge



      #!/bin/bash
      awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1


      Input:



      Affe : 3 : test
      Affe : 5 : test2
      Money : 9 : test3


      Outputs:



      $ ./merge t.txt
      Money ; 9:test3
      Affe ; 3:test 5:test2

      $ ./ascript2.awk t.txt
      Affe : 3 : test
      Affe : 5 : test2
      Money : 9 : test3
      Money ; 9 : test3
      Affe ; 3 : test; 5 : test2






      awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 9:21









      oguz ismail

      12.2k7 gold badges18 silver badges37 bronze badges




      12.2k7 gold badges18 silver badges37 bronze badges










      asked Mar 28 at 9:00









      Walter SchrabmairWalter Schrabmair

      4571 gold badge6 silver badges18 bronze badges




      4571 gold badge6 silver badges18 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          4
















          In ascript2.awk, a[$1]=a[$1] ";" $2 " : " $3 should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
          )



          So your script should look this:



          #!/usr/bin/awk -f
          BEGIN FS=":"
          a[$1] = a[$1] ";" $2 " : " $3
          END for (x in a) print x, a[x]





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393584%2fwhy-do-this-awk-script-print-the-original-file-too%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4
















            In ascript2.awk, a[$1]=a[$1] ";" $2 " : " $3 should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
            )



            So your script should look this:



            #!/usr/bin/awk -f
            BEGIN FS=":"
            a[$1] = a[$1] ";" $2 " : " $3
            END for (x in a) print x, a[x]





            share|improve this answer





























              4
















              In ascript2.awk, a[$1]=a[$1] ";" $2 " : " $3 should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
              )



              So your script should look this:



              #!/usr/bin/awk -f
              BEGIN FS=":"
              a[$1] = a[$1] ";" $2 " : " $3
              END for (x in a) print x, a[x]





              share|improve this answer



























                4














                4










                4









                In ascript2.awk, a[$1]=a[$1] ";" $2 " : " $3 should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
                )



                So your script should look this:



                #!/usr/bin/awk -f
                BEGIN FS=":"
                a[$1] = a[$1] ";" $2 " : " $3
                END for (x in a) print x, a[x]





                share|improve this answer













                In ascript2.awk, a[$1]=a[$1] ";" $2 " : " $3 should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
                )



                So your script should look this:



                #!/usr/bin/awk -f
                BEGIN FS=":"
                a[$1] = a[$1] ";" $2 " : " $3
                END for (x in a) print x, a[x]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 9:20









                oguz ismailoguz ismail

                12.2k7 gold badges18 silver badges37 bronze badges




                12.2k7 gold badges18 silver badges37 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393584%2fwhy-do-this-awk-script-print-the-original-file-too%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript