Welcome to the most active Linux Forum on the web.
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, 02:43 PM   #1
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, 02: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, 02:54 PM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try something like:
diff bindirectory binbase >cutdirectories.tmp
Old 11-08-2004, 07: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, 07: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 11:45 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 04:40 AM
bash-script: output text between two ocurrences of a specific string isl01jbe Programming 1 06-17-2004 03:36 PM
Identifying files in bash script Cruger Programming 7 03-15-2004 11:49 AM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 10:16 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 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
Open Source Consulting | Domain Registration