- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: help shell script: for and while
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
04-11-2007 09:34 AM
04-11-2007 09:34 AM
help shell script: for and while
in fileA I need to exclude domains from email that belong to another file
example fileA
cat fileA
yahoo.com
hotmail.com
hp.com
********************************
cat fileB
jhon@yahoo.com
postmaster@hotmail.com
**********************************
grep -v hotmail.com fileB --->this works
in script:
cat fileA|while read domain; do grep -v $domain fileB ; done
this not works
for i in `cat fileA`
do
grep -v $i fileB
done
this not works
the problem is the name@domain grep -v domain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2007 09:44 AM
04-11-2007 09:44 AM
Re: help shell script: for and while
cat fileA | while read domain
do
grep -q "${domain}" fileB 2>/dev/null
STAT=${?}
if [[ ${STAT} -eq 1 ]]
then
echo "${domain} not found in fileB"
fi
done
You only care if the pattern was found or not so use qrep -q and examine the exit status: 0 - was found 1 - was not found; other values would indicate an error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2007 10:06 AM
04-11-2007 10:06 AM
Re: help shell script: for and while
$ cat fileA|while read domain; do grep -q "${domain}" fileB; stat=$?; if [[ ${STAT} -eq 1 ]]; then echo "${domain} not found in fileB"; fi; done
$ echo $?
0
$
the $? is 0
fileA
hotmail.com
yahoo.com
hp.com
the fileB
john@yahoo.com
postmaster@hotmail.com
carl@next.com
grep -v hotmail.com fileB
grep -v yahoo.com fileB
...
I want to obtain fileC using while true
cat fileC
carl@next.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2007 10:25 AM
04-11-2007 10:25 AM
Re: help shell script: for and while
Try this:
------------------------------------
#!/usr/bin/sh
typeset C=""
typeset X=""
cat fileA | while read X
do
C="${C} -e \"${X}\""
done
eval grep -E -v "${C}" fileB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2007 10:42 AM
04-11-2007 10:42 AM
Re: help shell script: for and while
postmaster@hotmail.com
carl@next.com
ok , but it display the account postmaster@hotmail
I change the line script fileB for fileA position.
exclude account hotmail and yahoo.com of the fileB
that it contains the file fileA : yahoo.com hotmail.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2007 11:00 AM
04-11-2007 11:00 AM
Re: help shell script: for and while
I posted this in your other thread:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1117174
# cat fileA
yahoo.com
hotmail.com
hp.com
# cat fileB
jhon@yahoo.com
postmaster@hotmail.com
somebody@xyz.com
anotherbody@bigdot.com
# grep -F -v -f fileA fileB
somebody@xyz.com
anotherbody@bigdot.com
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2007 05:10 AM
04-12-2007 05:10 AM