44

Please explain what does following command mean:

awk -F: '{print $4}'

2 Answers 2

72
awk -F: '{print $4}'
  • awk - this is the interpreter for the AWK Programming Language. The AWK language is useful for manipulation of data files, text retrieval and processing
  • -F <value> - tells awk what field separator to use. In your case, -F: means that the separator is : (colon).
  • '{print $4}' means print the fourth field (the fields being separated by :).

Example:

Let's say that there's a file called test, and it contains the following:

Hello:my:name:is:Alaa

If we execute the command awk -F: '{print $4}' test, the output will be:

is

Because is is the fourth field.

      field1   field3  field5
       -----    ----    ----
       |   |    |  |    |  |
       Hello:my:name:is:Alaa
             ||      ||
             --      --
           field2  field4

0
9
  • You set the field separator with ...

    -F
    

    so that is ":" in this example.

  • You print the text that is between the 3th and 4th separator with ...

    '{print $4}'
    
  • And this explains it better:

    echo "154:266:377:454:533" | awk -F: '{print $4}'
    454
    
1
  • what if i want to print 454 154:266:377:454:533 print $4 and the entire line together separated by space?
    – Yogesh D
    Oct 12, 2017 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .