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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현