Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-23-2013
JSKOBS JSKOBS is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 1 July 2015, 2:51 AM EDT
Posts: 43
Thanks: 20
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 Unix and Linux 01-23-2013
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 4 July 2015, 5:46 AM EDT
Location: Zürich
Posts: 8,570
Thanks: 337
Thanked 1,080 Times in 938 Posts
grep.
Sponsored Links
    #3  
Old Unix and Linux 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 Unix and Linux 01-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 3 July 2015, 9:53 AM EDT
Location: Aachen, Germany
Posts: 6,243
Thanks: 109
Thanked 1,700 Times in 1,592 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 07:47 AM.