Quick Linux Tip:Print a line which contain some specific patterns using awk

A simple "awk" trick to match a pattern and print whole line containing matched pattern.

Awesome awk:

# cat <any_large_file/log>|awk '$3 ~ /<pattern to look for>/ {print $_}'

It will match a pattern in 3rd field of supplied file and if pattern found whole row/line will be printed on standard output.

OR simply:
                       #  awk -F ":" '$7 == "/bin/bash" {print "User:"$1 " Home Directory:"$6}' /etc/passwd

It will match 7th filed of  "/etc/passwd" and if true it will print first and 6th field of that file.

If you want complete line of matched pattern:
                      #    awk -F ":" '$7 == "/bin/bash" {print $0}' /etc/passwd

Popular posts from this blog

Grsecurity: Configure RHEL5/6 Kernel for Grsecurity

How to check Perl Module version in Linux

Linux Command line tips and Bash stuff