Por que imprimir funciona com o awk, mas o echo não funciona?

0

Para resumir ...

Isso funciona:

awk 'BEGIN { FS=":"; }
{ print  $1  $3  $5; }' /etc/passwd

Mas isso não acontece:

awk 'BEGIN { FS=":"; }
{ echo  $1  $3  $5; }' /etc/passwd

Sendo relativamente novo no aprendizado de bash, gostaria de saber por quê.

    
por user3271166 24.03.2016 / 05:24

1 resposta

2

A estrutura da execução awk é: pattern { action statements }

Actions
    Action statements are enclosed in braces, { and }. Action statements consist of the usual assignment, conditional, and looping statements found in most languages. The operators, control statements, and input/output statements available are patterned after those in C.

  • print é a declaração de E / S de awk .

    Da página de manual:

    print                 Print the current record.  The output record is terminated with the value of ORS.
    
  • Visite o manual > A declaração de impressão :

    The print Statement

    Use the print statement to produce output with simple, standardized formatting. You specify only the strings or numbers to print, in a list separated by commas. They are output, separated by single spaces, followed by a newline. The statement looks like this:

    print item1, item2, …
    

Visite man awk para mais detalhes.

Observe também que:

PATTERNS AND ACTIONS
       AWK is a line-oriented language.  The pattern comes  first,  and  then  the  action.   Action  statements  are
       enclosed  in  {  and  }.  Either the pattern may be missing, or the action may be missing, but, of course, not
       both.  If the pattern is missing, the action is executed for every single record of input.  A  missing  action
       is equivalent to

              { print }

       which prints the entire record.

awk não tem echo keyword / statement.

$ man awk | grep echo | wc -l
0
    
por 24.03.2016 / 05:38

Tags