Created
January 20, 2019 01:40
-
-
Save huangsam/fd9462a39dd4f002d26d1af0388951c5 to your computer and use it in GitHub Desktop.
Awk in action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
find . -name 'meta-*.yml' | xargs awk -F':' -f metadata.awk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- ip: 10.17.13.105 | |
hostname: spider.pic | |
expired: false | |
- ip: 8.8.8.8 | |
hostname: www.google.com | |
expired: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- ip: 10.17.11.101 | |
hostname: spider.pic | |
expired: false | |
- ip: 8.8.8.9 | |
hostname: www.google.com | |
expired: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN { | |
print "== metadata" | |
found = 0; | |
} | |
/ip:/ { | |
gsub(/ /, "", $NF); | |
printf "ip: [%s] | match: [%s]\n", $NF, $0; | |
found++; | |
} | |
/expired:/ { | |
gsub(/ /, "", $NF); | |
printf "ip: [%s] | match: [%s]\n", $NF, $0; | |
found++; | |
} | |
END { | |
if (found > 10) { | |
condition = "great" | |
} else if (found > 7) { | |
condition = "good" | |
} else if (found > 5) { | |
condition = "so-so" | |
} else { | |
condition = "bad" | |
} | |
printf "%s - %s\n", found, condition | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment