Why does this works :

echo 'NetRange:' | awk -F: '/NetRange/ {print $2}'

and this doesn't

echo 'NetRange:' | awk -F: 'NetRange {print $2}'

What is the purpose of / ?


It is similar to grep and find command -

Say for example - if you want to search for a word "hello" on a txt file "Firstprog.txt".

awk '/hello/' Firstprog.txt

This tells Awk to search through the file for lines of text that contain the string "hello", and print them out.

  • Thank you for fast answer , another thing , so this will print line no matter where 'hello' is located inside line?
    – Daniel
    Dec 5 '14 at 22:38
  • Yes, anywhere in the line. The stuff between the /.../ is a regular expression, so you can create very complex matches. Dec 5 '14 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.