- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need some scripting assistance....
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
Discussions
Discussions
Forums
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
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
тАО06-05-2007 10:55 AM
тАО06-05-2007 10:55 AM
I have a text file with 949 serial numbers in this format:
johnsonr@nmscrme01 > cat file
28991175
28991216
29591918
...
...
...
johnsonr@nmscrme01 >
What I need to do is search this file against several XML files to see if there are any matches and if so, what file is the match in?
Here's a script that basically says:
for each serial number in file, do a grep on several NC*.xml files in a certain directory.
However, I would like to make it where the output is redirected to another file say in the /tmp directory. Can someone help me out?
---Here's the script---
#!/bin/sh
for SN in `cat /opt/home/johnsonr/scripts/file`
do
grep $SN /opt/CSCOpx/htdocs/reports/NC*.xml
done
Here's output from the script which is fine.
johnsonr@nmscrme01 > ./snsearch.sh
/opt/CSCOpx/htdocs/reports/NC-DONPortCount.xml:
/opt/CSCOpx/htdocs/reports/NC-DONPortCount.xml:
/opt/CSCOpx/htdocs/reports/NC-DONPortCount.xml:
johnsonr@nmscrme01 >
I was thinking something along these lines but need assistance...
#!/bin/sh
for SN in `cat /opt/home/johnsonr/scripts/file`
do
grep $SN /opt/CSCOpx/htdocs/reports/NC*.xml
if [ $? -gt 0 ] -------this is the section i need the help in
then -------this is the section i need the help in
echo $results >> /tmp/SNFile -------this is the section i need the help in
fi -------this is the section i need the help in
done
Thanks in advance to all you scripters out there!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2007 11:54 AM
тАО06-05-2007 11:54 AM
Re: Need some scripting assistance....
#!/bin/sh
for SN in `cat /opt/home/johnsonr/scripts/file`
do
grep $SN /opt/CSCOpx/htdocs/reports/NC*.xml >> /tmp/SNFile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2007 11:55 AM
тАО06-05-2007 11:55 AM
SolutionYou can do something like this:
#!/usr/bin/sh
set -u
typeset TOKENS=/opt/home/johnsonr/scripts/file
typeset OUTPUT=/tmp/SNFile
rm "${OUTPUT}"
for SN in `cat ${TOKENS}`
do
grep ${SN} /opt/CSCOpx/htdocs/reports/NC*.xml /dev/null >> ${OUTPUT}
done
...By adding '/dev/null' to the file arguments to 'grep' the name of any file that constains a match is reported along with the match.
In keeping with the rule that "silence is golden", 'grep' will not output anything if there isn't at least one match.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2007 11:58 AM
тАО06-05-2007 11:58 AM
Re: Need some scripting assistance....
johnsonr@nmscrme01 > ./snsearch.sh >/tmp/SNFile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2007 03:41 PM
тАО06-05-2007 03:41 PM
Re: Need some scripting assistance....
$ grep -f /opt/home/johnsonr/scripts/file \
/opt/CSCOpx/htdocs/reports/NC*.xml /dev/null
If you only want the filename of the match, but not number you can add -l.
If you don't want to find your serial numbers in the middle of strings, you would use -w.