Need help writing for loop shell script
i am trying to write a script (which I havent done since college) that will grep each line from a file named Backlist which contains the titles of about 850 ebooks against another file named HQNlist which contains about 5500 lines which are book titles plus their corresponding ISBN codes. I want to be able to find those 850 matching titles and write them to a new file because I need to make a list of those ISBNs.
I wrote this script but it just writes the entire HQNlist many times to the new file: Code:
#!/bin/bash Thanks in advance |
Code:
cat Backlist | while read line; do |
I put your code into [CODE] tags to make it easier to read.
Sasha suggested the same approach that I was going to. To see why the original approach was not working, you could try inserting an echo statement to see the value of "line" each time thru the loop. |
I tried Sasha's approach. The results were just a blank file. Some of the lines have punctuation.
Is there a way to ignore special characters or should I try to remove all the punctuation from these files? |
How about show us a snippet of what's inside each file; that'd be the best way we can ensure that the grepping will work when it encounters odd characters.
|
whats the content of Backlist ?
could be there are spaces in each line. maybe you need to do something like: sed -n "$i"p instead. |
Quote:
You've Got Male The Darkest Facts: A Lords of the Underworld Companion The Darkest Fire The Amazon's Curse From HQNlist: Back on Blossom Street 9781426814686 Last Known Victim 9781426814693 The Healer 9781426814709 Rogue 9781426814716 does that sed command remove the spaces? |
use grep's -f option
Code:
grep -f backlist hnlist |
*delete*
|
Code:
echo "$(cat Backlist)" | while read line; do See if that works for you? SORRY - I initially left out the quotes around the `echo $(..)` which should be there -- please note that and correct.. |
Quote:
|
Quote:
|
This is weird colucix :scratch:
ghost*'s -f idea does not work for me, and neither does my initial suggestion which as you suggest should work with double-quotes (I changed the quotes and still no go). |
Quote:
I wish grep -f worked, it was the first thing i tried last night |
That's really weird. :scratch:
Here is my sample session: Code:
$ Backlist Code:
$ cat test.sh |
All times are GMT -5. The time now is 01:34 AM. |