awk print condtionHow to print the longest line in a file?Variable Substitution in Awk Print Statement...

Were Roman public roads build by private companies?

Does my opponent need to prove his creature has morph?

Could a Scotland-NI bridge break Brexit impasse?

How do email clients "send later" without storing a password?

How unbalanced coaxial cables are used for broadcasting TV signals without any problems?

When was the earliest opportunity the Voyager crew had to return to the Alpha quadrant?

Why would "an mule" be used instead of "a mule"?

Sol Ⅲ = Earth: What is the origin of this planetary naming scheme?

Parallel resistance in electric circuits

I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?

Might have gotten a coworker sick, should I address this?

Can the card disintegrate destroy creatures with indestructible?

Has SHA256 been broken by Treadwell Stanton DuPont?

What's the biggest organic molecule that could have a smell?

Is a suit against a Univeristy Dorm for changing policies on a whim likely to succeed (USA)?

How can I fix a framing mistake so I can drywall?

The Planck constant for mathematicians

Where can I get an anonymous Rav Kav card issued?

Why does Coq include let-expressions in its core language

Is English tonal for some words, like "permit"?

What is this unknown executable on my boot volume? Is it Malicious?

Is there any way to land a rover on the Moon without using any thrusters?

Maintenance tips to prolong engine lifespan for short trips

How do I get rid of distorted pictures of distant objects photographed with a telephoto lens?



awk print condtion


How to print the longest line in a file?Variable Substitution in Awk Print Statement -vFirst line of awk output isn't what I expectAwk print problemUsing variable with awk -v in a shell scriptHow to call bash function from within awk?Using getline with NR in awkcalculate ratio using awkAwk syntax, strange variable?






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







0















When i was debugging a file which was written by others, I found one line



psql -U crmlocal -h $2 -p 5432 mydb -c "set search_path=$3;$4" | awk 'NR>3 {print l} {l=$0}'


I don't know what



awk 'NR>3 {print l} {l=$0}' 


does this line actually do. Can anyone explain what does this line mean? {print l}










share|improve this question









New contributor



Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    0















    When i was debugging a file which was written by others, I found one line



    psql -U crmlocal -h $2 -p 5432 mydb -c "set search_path=$3;$4" | awk 'NR>3 {print l} {l=$0}'


    I don't know what



    awk 'NR>3 {print l} {l=$0}' 


    does this line actually do. Can anyone explain what does this line mean? {print l}










    share|improve this question









    New contributor



    Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0












      0








      0








      When i was debugging a file which was written by others, I found one line



      psql -U crmlocal -h $2 -p 5432 mydb -c "set search_path=$3;$4" | awk 'NR>3 {print l} {l=$0}'


      I don't know what



      awk 'NR>3 {print l} {l=$0}' 


      does this line actually do. Can anyone explain what does this line mean? {print l}










      share|improve this question









      New contributor



      Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      When i was debugging a file which was written by others, I found one line



      psql -U crmlocal -h $2 -p 5432 mydb -c "set search_path=$3;$4" | awk 'NR>3 {print l} {l=$0}'


      I don't know what



      awk 'NR>3 {print l} {l=$0}' 


      does this line actually do. Can anyone explain what does this line mean? {print l}







      awk






      share|improve this question









      New contributor



      Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 9 mins ago









      Inian

      7,20517 silver badges36 bronze badges




      7,20517 silver badges36 bronze badges






      New contributor



      Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 22 mins ago









      Hari BharathiHari Bharathi

      11 bronze badge




      11 bronze badge




      New contributor



      Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Hari Bharathi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          1 Answer
          1






          active

          oldest

          votes


















          1
















          A simpler input to explain the command:



          $ seq 6 | awk 'NR>3 {print l} {l=$0}'
          3
          4
          5




          • NR is a special variable that has the value of current record number (same as line number in this case)


            • so NR>3 means line number greater than 3




          • {l=$0} this is saving contents of current line (special variable $0) to a user defined variable l


          • NR>3 {print l} when the condition is true, print contents of variable l


          So, effectively, this code prints all lines from input except first two lines and the last line.






          share|improve this answer




























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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
            });


            }
            });







            Hari Bharathi is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded
















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f541304%2fawk-print-condtion%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









            1
















            A simpler input to explain the command:



            $ seq 6 | awk 'NR>3 {print l} {l=$0}'
            3
            4
            5




            • NR is a special variable that has the value of current record number (same as line number in this case)


              • so NR>3 means line number greater than 3




            • {l=$0} this is saving contents of current line (special variable $0) to a user defined variable l


            • NR>3 {print l} when the condition is true, print contents of variable l


            So, effectively, this code prints all lines from input except first two lines and the last line.






            share|improve this answer






























              1
















              A simpler input to explain the command:



              $ seq 6 | awk 'NR>3 {print l} {l=$0}'
              3
              4
              5




              • NR is a special variable that has the value of current record number (same as line number in this case)


                • so NR>3 means line number greater than 3




              • {l=$0} this is saving contents of current line (special variable $0) to a user defined variable l


              • NR>3 {print l} when the condition is true, print contents of variable l


              So, effectively, this code prints all lines from input except first two lines and the last line.






              share|improve this answer




























                1














                1










                1









                A simpler input to explain the command:



                $ seq 6 | awk 'NR>3 {print l} {l=$0}'
                3
                4
                5




                • NR is a special variable that has the value of current record number (same as line number in this case)


                  • so NR>3 means line number greater than 3




                • {l=$0} this is saving contents of current line (special variable $0) to a user defined variable l


                • NR>3 {print l} when the condition is true, print contents of variable l


                So, effectively, this code prints all lines from input except first two lines and the last line.






                share|improve this answer













                A simpler input to explain the command:



                $ seq 6 | awk 'NR>3 {print l} {l=$0}'
                3
                4
                5




                • NR is a special variable that has the value of current record number (same as line number in this case)


                  • so NR>3 means line number greater than 3




                • {l=$0} this is saving contents of current line (special variable $0) to a user defined variable l


                • NR>3 {print l} when the condition is true, print contents of variable l


                So, effectively, this code prints all lines from input except first two lines and the last line.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 14 mins ago









                SundeepSundeep

                7,7861 gold badge11 silver badges28 bronze badges




                7,7861 gold badge11 silver badges28 bronze badges


























                    Hari Bharathi is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded

















                    Hari Bharathi is a new contributor. Be nice, and check out our Code of Conduct.













                    Hari Bharathi is a new contributor. Be nice, and check out our Code of Conduct.












                    Hari Bharathi is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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%2funix.stackexchange.com%2fquestions%2f541304%2fawk-print-condtion%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

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...