When interpret awk as a command or a programming language?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I know that awk is a script programming language, but sometimes I get confused about when I interpret as command or as a program.



Eg. 1 - Here I interpret as a command:



awk 'print $2' file.txt


Eg. 2 - Here I interpret as a awk program:



awk 'BEGIN skip = 0 
skip == 0 if (NF == 0)
skip = 1
else
print;
next
skip == 1 print;
skip = 0;
next'


Taken from here.



The questions are:



  1. When awk need be interpreted as a command?

  2. When awk is a program?

  3. There's a problem call my first example as a awk command?

Something like:



awk 'print $2' file.txt | awk 'FS=" " print 4'


means that awk programs can communicate using pipes?










share|improve this question



















  • 2





    Your question doesn't really make a lot of sense. Most commands are programs (with notable exceptions); most programs are commands. awk, like cat and ls, is both a command and a program. The awk program/command is an interpreter for a language which, apparently, is called "AWK". The string following the awk command -- even if it's as little as print $2 -- is an AWK program. If you say awk -f foo, then the file foo (or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs, awk processes can have their I/O redirected to files and pipes.

    – G-Man
    Oct 16 '14 at 17:48















0















I know that awk is a script programming language, but sometimes I get confused about when I interpret as command or as a program.



Eg. 1 - Here I interpret as a command:



awk 'print $2' file.txt


Eg. 2 - Here I interpret as a awk program:



awk 'BEGIN skip = 0 
skip == 0 if (NF == 0)
skip = 1
else
print;
next
skip == 1 print;
skip = 0;
next'


Taken from here.



The questions are:



  1. When awk need be interpreted as a command?

  2. When awk is a program?

  3. There's a problem call my first example as a awk command?

Something like:



awk 'print $2' file.txt | awk 'FS=" " print 4'


means that awk programs can communicate using pipes?










share|improve this question



















  • 2





    Your question doesn't really make a lot of sense. Most commands are programs (with notable exceptions); most programs are commands. awk, like cat and ls, is both a command and a program. The awk program/command is an interpreter for a language which, apparently, is called "AWK". The string following the awk command -- even if it's as little as print $2 -- is an AWK program. If you say awk -f foo, then the file foo (or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs, awk processes can have their I/O redirected to files and pipes.

    – G-Man
    Oct 16 '14 at 17:48













0












0








0








I know that awk is a script programming language, but sometimes I get confused about when I interpret as command or as a program.



Eg. 1 - Here I interpret as a command:



awk 'print $2' file.txt


Eg. 2 - Here I interpret as a awk program:



awk 'BEGIN skip = 0 
skip == 0 if (NF == 0)
skip = 1
else
print;
next
skip == 1 print;
skip = 0;
next'


Taken from here.



The questions are:



  1. When awk need be interpreted as a command?

  2. When awk is a program?

  3. There's a problem call my first example as a awk command?

Something like:



awk 'print $2' file.txt | awk 'FS=" " print 4'


means that awk programs can communicate using pipes?










share|improve this question
















I know that awk is a script programming language, but sometimes I get confused about when I interpret as command or as a program.



Eg. 1 - Here I interpret as a command:



awk 'print $2' file.txt


Eg. 2 - Here I interpret as a awk program:



awk 'BEGIN skip = 0 
skip == 0 if (NF == 0)
skip = 1
else
print;
next
skip == 1 print;
skip = 0;
next'


Taken from here.



The questions are:



  1. When awk need be interpreted as a command?

  2. When awk is a program?

  3. There's a problem call my first example as a awk command?

Something like:



awk 'print $2' file.txt | awk 'FS=" " print 4'


means that awk programs can communicate using pipes?







awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 16 '14 at 10:39









cuonglm

104k24204302




104k24204302










asked Oct 16 '14 at 10:04









ColdCold

1,3934910




1,3934910







  • 2





    Your question doesn't really make a lot of sense. Most commands are programs (with notable exceptions); most programs are commands. awk, like cat and ls, is both a command and a program. The awk program/command is an interpreter for a language which, apparently, is called "AWK". The string following the awk command -- even if it's as little as print $2 -- is an AWK program. If you say awk -f foo, then the file foo (or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs, awk processes can have their I/O redirected to files and pipes.

    – G-Man
    Oct 16 '14 at 17:48












  • 2





    Your question doesn't really make a lot of sense. Most commands are programs (with notable exceptions); most programs are commands. awk, like cat and ls, is both a command and a program. The awk program/command is an interpreter for a language which, apparently, is called "AWK". The string following the awk command -- even if it's as little as print $2 -- is an AWK program. If you say awk -f foo, then the file foo (or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs, awk processes can have their I/O redirected to files and pipes.

    – G-Man
    Oct 16 '14 at 17:48







2




2





Your question doesn't really make a lot of sense. Most commands are programs (with notable exceptions); most programs are commands. awk, like cat and ls, is both a command and a program. The awk program/command is an interpreter for a language which, apparently, is called "AWK". The string following the awk command -- even if it's as little as print $2 -- is an AWK program. If you say awk -f foo, then the file foo (or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs, awk processes can have their I/O redirected to files and pipes.

– G-Man
Oct 16 '14 at 17:48





Your question doesn't really make a lot of sense. Most commands are programs (with notable exceptions); most programs are commands. awk, like cat and ls, is both a command and a program. The awk program/command is an interpreter for a language which, apparently, is called "AWK". The string following the awk command -- even if it's as little as print $2 -- is an AWK program. If you say awk -f foo, then the file foo (or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs, awk processes can have their I/O redirected to files and pipes.

– G-Man
Oct 16 '14 at 17:48










2 Answers
2






active

oldest

votes


















4














awk has two modes of invocation one is with a program text on the command line and the other with a program from a file. This is stated in the synopsis of the awk man page (this one from mawk on Ubuntu 12.04):



 mawk [-W option] [-F value] [-v var=value] [--] 'program text' [file
...]
mawk [-W option] [-F value] [-v var=value] [-f program-file] [--]
[file ...]


Whether to call the first form a program or not depends on the definition of program you want use. I would say both forms involve programs, whereby on the first the program is specified as a commandline argument. Both of your examples to be of the first form, as neither involves the -f option. That the second example has a multiline commandline argument is, with respect to this, irrelevant.



This is not unique to awk. e.g. python by defaults interprets a commandline argument as a program name, but with the -c option allows you to specify a program on the commandline (i.e. the default is the other way around from awk).



Independent of that is the communication using pipes. That is taken care of by the shell syntax and the OS, the only thing your script needs to do is write to stdout, reps. read from stdin. So yes awk programs can communicate over pipes.






share|improve this answer

























  • Thanks @Anthon (including the edition). Growing and learning.

    – Cold
    Oct 16 '14 at 10:27


















3














Strictly speaking, when you call awk, you refer to the interpreter, not the language. The language is called AWK.



awk (or mawk, nawk) is only utility, which will execute programs written in AWK programming language.



As POSIX defined, awk program is:




program



If no -f option is specified, the first operand to awk shall be the
text of the awk program. The application shall supply the program
operand as a single argument to awk. If the text does not end in a
, awk shall interpret the text as if it did.




So if you don't use -f option, you can consider two of your examples as awk program.






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/3.0/"u003ecc by-sa 3.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%2funix.stackexchange.com%2fquestions%2f162459%2fwhen-interpret-awk-as-a-command-or-a-programming-language%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    awk has two modes of invocation one is with a program text on the command line and the other with a program from a file. This is stated in the synopsis of the awk man page (this one from mawk on Ubuntu 12.04):



     mawk [-W option] [-F value] [-v var=value] [--] 'program text' [file
    ...]
    mawk [-W option] [-F value] [-v var=value] [-f program-file] [--]
    [file ...]


    Whether to call the first form a program or not depends on the definition of program you want use. I would say both forms involve programs, whereby on the first the program is specified as a commandline argument. Both of your examples to be of the first form, as neither involves the -f option. That the second example has a multiline commandline argument is, with respect to this, irrelevant.



    This is not unique to awk. e.g. python by defaults interprets a commandline argument as a program name, but with the -c option allows you to specify a program on the commandline (i.e. the default is the other way around from awk).



    Independent of that is the communication using pipes. That is taken care of by the shell syntax and the OS, the only thing your script needs to do is write to stdout, reps. read from stdin. So yes awk programs can communicate over pipes.






    share|improve this answer

























    • Thanks @Anthon (including the edition). Growing and learning.

      – Cold
      Oct 16 '14 at 10:27















    4














    awk has two modes of invocation one is with a program text on the command line and the other with a program from a file. This is stated in the synopsis of the awk man page (this one from mawk on Ubuntu 12.04):



     mawk [-W option] [-F value] [-v var=value] [--] 'program text' [file
    ...]
    mawk [-W option] [-F value] [-v var=value] [-f program-file] [--]
    [file ...]


    Whether to call the first form a program or not depends on the definition of program you want use. I would say both forms involve programs, whereby on the first the program is specified as a commandline argument. Both of your examples to be of the first form, as neither involves the -f option. That the second example has a multiline commandline argument is, with respect to this, irrelevant.



    This is not unique to awk. e.g. python by defaults interprets a commandline argument as a program name, but with the -c option allows you to specify a program on the commandline (i.e. the default is the other way around from awk).



    Independent of that is the communication using pipes. That is taken care of by the shell syntax and the OS, the only thing your script needs to do is write to stdout, reps. read from stdin. So yes awk programs can communicate over pipes.






    share|improve this answer

























    • Thanks @Anthon (including the edition). Growing and learning.

      – Cold
      Oct 16 '14 at 10:27













    4












    4








    4







    awk has two modes of invocation one is with a program text on the command line and the other with a program from a file. This is stated in the synopsis of the awk man page (this one from mawk on Ubuntu 12.04):



     mawk [-W option] [-F value] [-v var=value] [--] 'program text' [file
    ...]
    mawk [-W option] [-F value] [-v var=value] [-f program-file] [--]
    [file ...]


    Whether to call the first form a program or not depends on the definition of program you want use. I would say both forms involve programs, whereby on the first the program is specified as a commandline argument. Both of your examples to be of the first form, as neither involves the -f option. That the second example has a multiline commandline argument is, with respect to this, irrelevant.



    This is not unique to awk. e.g. python by defaults interprets a commandline argument as a program name, but with the -c option allows you to specify a program on the commandline (i.e. the default is the other way around from awk).



    Independent of that is the communication using pipes. That is taken care of by the shell syntax and the OS, the only thing your script needs to do is write to stdout, reps. read from stdin. So yes awk programs can communicate over pipes.






    share|improve this answer















    awk has two modes of invocation one is with a program text on the command line and the other with a program from a file. This is stated in the synopsis of the awk man page (this one from mawk on Ubuntu 12.04):



     mawk [-W option] [-F value] [-v var=value] [--] 'program text' [file
    ...]
    mawk [-W option] [-F value] [-v var=value] [-f program-file] [--]
    [file ...]


    Whether to call the first form a program or not depends on the definition of program you want use. I would say both forms involve programs, whereby on the first the program is specified as a commandline argument. Both of your examples to be of the first form, as neither involves the -f option. That the second example has a multiline commandline argument is, with respect to this, irrelevant.



    This is not unique to awk. e.g. python by defaults interprets a commandline argument as a program name, but with the -c option allows you to specify a program on the commandline (i.e. the default is the other way around from awk).



    Independent of that is the communication using pipes. That is taken care of by the shell syntax and the OS, the only thing your script needs to do is write to stdout, reps. read from stdin. So yes awk programs can communicate over pipes.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 28 at 21:10









    Jeff Schaller

    41.5k1056132




    41.5k1056132










    answered Oct 16 '14 at 10:10









    AnthonAnthon

    60.9k17103166




    60.9k17103166












    • Thanks @Anthon (including the edition). Growing and learning.

      – Cold
      Oct 16 '14 at 10:27

















    • Thanks @Anthon (including the edition). Growing and learning.

      – Cold
      Oct 16 '14 at 10:27
















    Thanks @Anthon (including the edition). Growing and learning.

    – Cold
    Oct 16 '14 at 10:27





    Thanks @Anthon (including the edition). Growing and learning.

    – Cold
    Oct 16 '14 at 10:27













    3














    Strictly speaking, when you call awk, you refer to the interpreter, not the language. The language is called AWK.



    awk (or mawk, nawk) is only utility, which will execute programs written in AWK programming language.



    As POSIX defined, awk program is:




    program



    If no -f option is specified, the first operand to awk shall be the
    text of the awk program. The application shall supply the program
    operand as a single argument to awk. If the text does not end in a
    , awk shall interpret the text as if it did.




    So if you don't use -f option, you can consider two of your examples as awk program.






    share|improve this answer



























      3














      Strictly speaking, when you call awk, you refer to the interpreter, not the language. The language is called AWK.



      awk (or mawk, nawk) is only utility, which will execute programs written in AWK programming language.



      As POSIX defined, awk program is:




      program



      If no -f option is specified, the first operand to awk shall be the
      text of the awk program. The application shall supply the program
      operand as a single argument to awk. If the text does not end in a
      , awk shall interpret the text as if it did.




      So if you don't use -f option, you can consider two of your examples as awk program.






      share|improve this answer

























        3












        3








        3







        Strictly speaking, when you call awk, you refer to the interpreter, not the language. The language is called AWK.



        awk (or mawk, nawk) is only utility, which will execute programs written in AWK programming language.



        As POSIX defined, awk program is:




        program



        If no -f option is specified, the first operand to awk shall be the
        text of the awk program. The application shall supply the program
        operand as a single argument to awk. If the text does not end in a
        , awk shall interpret the text as if it did.




        So if you don't use -f option, you can consider two of your examples as awk program.






        share|improve this answer













        Strictly speaking, when you call awk, you refer to the interpreter, not the language. The language is called AWK.



        awk (or mawk, nawk) is only utility, which will execute programs written in AWK programming language.



        As POSIX defined, awk program is:




        program



        If no -f option is specified, the first operand to awk shall be the
        text of the awk program. The application shall supply the program
        operand as a single argument to awk. If the text does not end in a
        , awk shall interpret the text as if it did.




        So if you don't use -f option, you can consider two of your examples as awk program.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 16 '14 at 10:31









        cuonglmcuonglm

        104k24204302




        104k24204302



























            draft saved

            draft discarded
















































            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%2f162459%2fwhen-interpret-awk-as-a-command-or-a-programming-language%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

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay