- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 05:21 PM
07-22-2003 05:21 PM
I have a quick query about a script I am trying to put together
I have a file full of address' I need to check wether the address' in the file resides in other files
I have put this together at the moment
for match in $(cat nomatch_add.dat)
do
newmatch=\'$match\'
grep $newmatch
if [ $? = 0 ]
then
num=$(cat /tmp/totals)
echo "$match exists in
fi
done
The problem I am having is with the newmatch. I thought that if I add ' to the start and end of the variable then grep would treat the variable as one entry to match.
echo $match
2 HARROW LANE
newmatch=\'$match\'
echo $newmatch
'2 HARROW LANE'
I get this though
grep $newmatch
grep: can't open HARROW
grep: can't open LANE
grep: can't open '
How can I resolve this
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 05:28 PM
07-22-2003 05:28 PM
Re: script help
Put "" around the grep string as follows:
grep "$newmatch"
At the moment grep is trying to find 2 in the filenames HARROW and LANE.
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 05:30 PM
07-22-2003 05:30 PM
Re: script help
Hence your error.
try this
grep steve man
you get
grep: can't open man
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 05:38 PM
07-22-2003 05:38 PM
Solution#!/usr/bin/sh
while read match
do
grep "$match"
if [ $? = 0 ]
then
num=$(cat /tmp/totals)
echo "$match exists in
fi
done < nomatch_add.dat
If you want to shorten it even more:
while read match
do
num=$(grep "$match"
echo "$match exists in
done < nomatch_add.dat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 05:43 PM
07-22-2003 05:43 PM
Re: script help
Stephen,
Thats why I encased the 2 HARROW LANE in ' '
Con
I tried that but
echo "$newmatch"
'2 HARROW ROAD'
grep "$newmatch"
The above doesn't return anything, yet
tail -1
2 HARROW ROAD
As it is trying to match '2 HARROW ROAD'
I have therefore dropped the ' ' from the 2 HARROW ROAD
Gone back to $match and simply encased the $match with " "
grep "$match"
doh !!!!
fundamentals me thinks
Thanks for the replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 05:52 PM
07-22-2003 05:52 PM
Re: script help
while read match
do
num=$(grep "$match"
echo "$match exists in
done < nomatch_add.dat
would be
while read match
do
num=$(grep -c "$match"
echo "$match exists in
done < nomatch_add.dat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 06:00 PM
07-22-2003 06:00 PM
Re: script help
Seems' I have another issue
for match in `cat
do
echo $match
2
HARROW
ROAD
uhh!!!!
cat
2 HARROW ROAD
Why is this ???
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 06:06 PM
07-22-2003 06:06 PM
Re: script help
Have ammended to
cat
Seems to have done the trick
Thanks everyone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2003 06:22 PM
07-22-2003 06:22 PM
Re: script help
file="nomatch_add.dat"
cat $file |
while read match
do
printf "$match exists in $file %d times\n" $(awk '/'"$match"'/ {t++;} END {print t;}' $file)
done