Need command | Unix Linux Forums | Solaris

  Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Need command

Solaris


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-23-2013
JSKOBS JSKOBS is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 21 February 2014, 3:59 AM EST
Posts: 33
Thanks: 11
Thanked 0 Times in 0 Posts
Need command

I have two files File1, File2. File1 has whole list of IDs and File2 has a limited IDs. i need to compare these two files and take the IDs which are not present in File2 but present in File1. can someone tell me a command.
Sponsored Links
    #2  
Old 01-23-2013
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 24 July 2014, 12:59 PM EDT
Location: Zürich
Posts: 8,421
Thanks: 328
Thanked 1,028 Times in 899 Posts
grep.
Sponsored Links
    #3  
Old 01-23-2013
GP81 GP81 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 13 January 2014, 7:20 AM EST
Location: Warsaw, Poland
Posts: 65
Thanks: 0
Thanked 14 Times in 13 Posts
Maybe some script?

Code:
#!/bin/sh
cat $1 | while read LINE; do
 exist=`grep $LINE $2`
 if [ ! -z $exist ]; then
  echo $exist >> exists_in_file1.txt
 fi
done


Code:
server1 # ./diff.sh file1 file2

I assume that each line has only one ID. If your files are large, then performance of that script can be a problem.
Of course Scott has right and grep work fine too:

Code:
server1 # grep -f file1 file2

The Following User Says Thank You to GP81 For This Useful Post:
JSKOBS (01-23-2013)
    #4  
Old 01-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 24 July 2014, 9:47 AM EDT
Location: Aachen, Germany
Posts: 3,871
Thanks: 62
Thanked 919 Times in 872 Posts
Try
Code:
grep -vf File2 File1

The Following User Says Thank You to RudiC For This Useful Post:
JSKOBS (01-23-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing command output from one command to the next command in cshell kaaliakahn UNIX for Dummies Questions & Answers 2 02-10-2012 04:59 PM
Need help! command working ok when executed in command line, but fails when run inside a script! 4dirk1 Shell Programming and Scripting 4 12-02-2010 05:47 AM
AIX:Command to get netaddress/subnet address command in IPv4/IP6 rookie8278 AIX 2 06-17-2009 11:35 AM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 06:54 AM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 08:26 AM



All times are GMT -4. The time now is 01:42 PM.