Register a domain and help support LQ
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-08-2004, 01:43 PM   #1
Registered: Sep 2003
Location: Suwon, Korea
Distribution: Slackware 13
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
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
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

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

Rep: Reputation: 0
You could use the comm command

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

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 01:54 AM.

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