- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep to compare two files...
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
тАО11-12-2010 07:07 AM
тАО11-12-2010 07:07 AM
grep to compare two files...
I am having two list of nodes. i want to compare them and make the list of nodes present in fair and missing in app1
ie,
grep $NODE app1-node-list >>present
if $NODE not present in app1 node list, i want to write it in a new file...how to do that please....
root@fair> ll
total 224
-rw-r--r-- 1 root sys 85757 Nov 12 01:47 app1-node-list
-rw-r--r-- 1 root sys 19198 Nov 12 08:25 fair-node-list
root@fair>
root@fair> for NODE in `cat fair-node-list`
> do
> grep $NODE app1-node-list >>present
> done
root@fair> ll
total 256
-rw-r--r-- 1 root sys 85757 Nov 12 01:47 app1-node-list
-rw-r--r-- 1 root sys 19198 Nov 12 08:25 fair-node-list
-rw-r--r-- 1 root sys 14017 Nov 12 09:28 present
root@fair> wc *
7637 7660 85757 app1-node-list
1576 1570 19198 fair-node-list
1192 1192 14017 present
10405 10422 118972 total
root@fair>
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 07:33 AM
тАО11-12-2010 07:33 AM
Re: grep to compare two files...
grep -f app1-node-list fair-node-list
Beware that the lines in the first file mentioned are treated as regular expression PATTERNs.
So depending on needs, feeds and the exact platform being used you may want to add any or all of:
-i, ignore case distinctions
-w, force PATTERN to match only whole words
-x, force PATTERN to match only whole lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 08:27 AM
тАО11-12-2010 08:27 AM
Re: grep to compare two files...
grep -f app1-node-list fairlane-node-list |wc
1576 1570 19198
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 08:55 AM
тАО11-12-2010 08:55 AM
Re: grep to compare two files...
I missed out the NOT, for grep that is: -v
It this what you desire:
# cat fair-node-list
aap
noot
kees
# cat app1-node-list
aap
noot
mies
vuur
# grep -v -f app1-node-list fair-node-list
kees
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2010 09:08 AM
тАО11-12-2010 09:08 AM
Re: grep to compare two files...
Using 'comm' assumes sorted files. Using Hein's files and their contents:
# comm -13 app1-node-list fair-node-list
kees
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2010 10:24 PM
тАО11-13-2010 10:24 PM
Re: grep to compare two files...
#if $NODE is present in node.list, update that to present.txt
grep $NODE node.list >>present.txt
#if $NODE is not present in this node.list, how to check that condition? will this below if loop will work?
if [ `grep $NODE node.list` ==0 ]
then
echo $NODE >>not.present.txt
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2010 02:48 AM
тАО11-14-2010 02:48 AM
Re: grep to compare two files...
You need to clean it up a little:
grep -q $NODE node.list
if [ $? -ne 0 ]; then
echo $NODE >> not.present.txt
fi