Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have 2 files.
- The first file contains a list of names. The second file is a book. I want to count how many times each name occurs in the book.
- I found this Stackoverflow answer: https://unix.stackexchange.com/a/2245/110855
- I want to use grep -c '\<WORD\>', whoever, I believe the variable is lost in my pipe.
- Example code:
- # Assume first file is names.txt and second file is book.txt
- book=$(cat book.txt)
- cat names.txt | while read name; do
- echo $book | grep -c '\<$name\>'
- done
- The above code simply prints out 0. I would assume it would iterate through each name. If I execute
- echo $book | grep -c '\<John\>'
- it works as expected and prints how many times the name John appears in the book. I'm assuming this is an issue with losing the variable in the pipe.
- Any help? Thanks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement