April
8
Linux: Using grep
Word count
grep -o ‘word’ filename | wc -l
One liner to find a running process and kill it
kill $(ps aux |grep -i ‘[/]usr/bin/puppet’ | awk ‘{print $2}’)
Find duplicate words in a file
grep -wo ‘[[:alnum:][:punct:]]+’ filename.txt | sort | uniq -cd
- You may need to vary the “bracket expressions”, to fit the characters you are tryin go match.
The above worked well when looking to find more than one server that is using the FQDN.
Search filesystem for a word:
find / -xdev -type f -print0 | xargs -0 grep -H “wordtosearchfor”