Skip to content

Instantly share code, notes, and snippets.

@fsmithred
Created July 3, 2012 10:59
Show Gist options
  • Select an option

  • Save fsmithred/3039075 to your computer and use it in GitHub Desktop.

Select an option

Save fsmithred/3039075 to your computer and use it in GitHub Desktop.
use awk to find a variable
#!/usr/bin/env bash
# test_awk
username="user"
awk -v pattern="$username" -F: '$0 ~ pattern { print $5 }' /etc/passwd
echo "-----"
awk -v pattern="$username" -F: '$1 ~ pattern { print $5 }' /etc/passwd
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment