LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-08-2004, 01:43 PM   #1
czarherr
Member
 
Registered: Sep 2003
Location: Suwon, Korea
Distribution: Slackware 14
Posts: 288

Rep: Reputation: 32
bash script to output only differences in two files


I am writing a script that will output an ls command to a file, and compare that file to one that will already exist. I need the script to compare the two files, and output only the lines in the ls that don't appear in the preexisting file. For example, it will ls the programs in /bin, and redirect it to the bindirectory file it will create. It will then check the bindirectory file against one I will have made prior to this, binbase, and take the differences in the two, and output it to the cutdirectories.tmp file. I just need to know how to get only the differing lines.
 
Old 11-08-2004, 01:49 PM   #2
gmartin
Member
 
Registered: Mar 2003
Location: PA
Distribution: Slackware 13.37 Linux Reg # 341245
Posts: 285

Rep: Reputation: 40
Take a look at the diff command.
 
Old 11-08-2004, 01:54 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try something like:
Code:
diff bindirectory binbase >cutdirectories.tmp
 
Old 11-08-2004, 06:13 PM   #4
dannyp
LQ Newbie
 
Registered: Mar 2004
Location: Philadelphia, PA
Posts: 14

Rep: Reputation: 0
You could use the comm command

Code:
comm -12 file1 file2
 
Old 11-08-2004, 06:25 PM   #5
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
I thought diff was a better comm?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to delete files c0d3 Programming 9 12-05-2004 10:45 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 03:40 AM
bash-script: output text between two ocurrences of a specific string isl01jbe Programming 1 06-17-2004 02:36 PM
Identifying files in bash script Cruger Programming 7 03-15-2004 10:49 AM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 09:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration