Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic

> need help with shell script
hsp40oz
post Jul 22 2010, 11:54 PM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 1
Joined: 22-July 10
Member No.: 15,618



i am trying to write a script (or use a command) 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 to the new file:

#!/bin/bash
for line in `cat Backlist`
do
grep -i $line HQNlist >> results.omfg
done

Any ideas?

Thanks in advance
Go to the top of the page
 
+Quote Post
listat
post Aug 11 2010, 02:09 PM
Post #2


Whats this Lie-nix Thing?
*

Group: Members
Posts: 5
Joined: 11-August 10
From: England
Member No.: 15,699



QUOTE (hsp40oz @ Jul 23 2010, 04:54 AM) *
i am trying to write a script (or use a command) 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 to the new file:

#!/bin/bash
for line in `cat Backlist`
do
grep -i $line HQNlist >> results.omfg
done

Any ideas?

Thanks in advance


Yes, try looking at the contents of results.omfg
After looking at the script I tried it myself and assuming that Backlist and HQNlist are in the same directory then then script works.
The only thing to watch out for is duplicate entries where the title in Backlist is (eg) LOTR, and the HQNlist contains LOTR I, LOTR II and LOTR III as it will consider all three as hits.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 8th September 2010 - 05:33 AM