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


Closed Thread    
Thread Tools Search this Thread Display Modes
Old 01-23-2013
JSKOBS JSKOBS is offline
Registered User
Join Date: Sep 2010
Last Activity: 5 February 2015, 4:56 AM EST
Posts: 38
Thanks: 19
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
Old 01-23-2013
Scott's Avatar
Scott Scott is online now Forum Staff  
Join Date: Jun 2009
Last Activity: 1 March 2015, 3:49 PM EST
Location: Zürich
Posts: 8,515
Thanks: 336
Thanked 1,059 Times in 923 Posts
Sponsored Links
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?

cat $1 | while read LINE; do
 exist=`grep $LINE $2`
 if [ ! -z $exist ]; then
  echo $exist >> exists_in_file1.txt

server1 # ./ 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:

server1 # grep -f file1 file2

The Following User Says Thank You to GP81 For This Useful Post:
JSKOBS (01-23-2013)
Old 01-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
Join Date: Jul 2012
Last Activity: 1 March 2015, 12:06 PM EST
Location: Aachen, Germany
Posts: 5,413
Thanks: 94
Thanked 1,409 Times in 1,327 Posts
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 05: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 06:47 AM
AIX:Command to get netaddress/subnet address command in IPv4/IP6 rookie8278 AIX 2 06-17-2009 12:35 PM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 07:54 AM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 09:26 AM

All times are GMT -4. The time now is 04:53 PM.