1

Why does this works :

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

and this doesn't

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

What is the purpose of / ?

1

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.

2
  • 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.