Skip to content

Instantly share code, notes, and snippets.

@DanCoughlin
Created September 10, 2015 00:38
Show Gist options
  • Save DanCoughlin/ae93115f2d6b3e726664 to your computer and use it in GitHub Desktop.
Save DanCoughlin/ae93115f2d6b3e726664 to your computer and use it in GitHub Desktop.
searching a file provided for key words provided and printing the number of times it has been found.
#!/bin/bash
# give counts for two different variables
# for any file passed
# and output the values
n1=`grep -i $1 $3 | wc -l`
n2=`grep -i $2 $3 | wc -l`
# output the values
echo In file: $3
echo I found $1 $n1 times
echo I found $2 $n2 times
@DanCoughlin
Copy link
Author

What happens if I run the file with the wrong number of arguments?
$./week3challenge.sh yay example.csv
Can you add error checking to make sure the appropriate number of arguments have been given?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment