Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Compare all files in directory, list filenames only

  • 03-03-2011 07:21PM
    #1
    Registered Users, Registered Users 2 Posts: 6,475 ✭✭✭


    This should be very simple, but I'm making a hash of it. Probably cos my Unix scripting knowledge is minimal :)

    I've got some software for which I have my own amended versions of some of the files. When a new release of the software comes out, I want to find out if I have local versions of any of the base files have changed, as I may need to incorporate those changes.

    I'm installing the new version in parallel anyway, so the simplest thing to do would be a diff of the old base files against the new base files to find what files have changed, and then a diff of the those against my files.

    So something like:
    diff -ru oldbase newbase > basediff.txt
    for filename in `cat basediff.txt`
    do 
    diff myfiles/filename newbase/filename >> mydiff.txt
    done
    

    However, I need the first diff to only list the filenames, instead of 'files oldbase/filename and newbase/filename differ' and 'only in newbase: filename' In fact, I don't care about new base files either, only changed ones.

    I've been through the diff man page but can't find a way of just listing the filenames. An alternative would probably be a regexp when reading the basediff.txt file to extract the filename, but no sure how to do that in a script.


Comments

  • Registered Users, Registered Users 2 Posts: 218 ✭✭Tillotson


    That is going to get very complicated very fast. I'd recommend using some sort of version control such as git.

    This tutorial is probably enough to get you started


  • Registered Users, Registered Users 2 Posts: 6,475 ✭✭✭MOH


    Tillotson wrote: »
    That is going to get very complicated very fast. I'd recommend using some sort of version control such as git.

    This tutorial is probably enough to get you started

    Yeah, I know. Thanks, I'll have a look at that - it's a bit messy in that I'm on a shared server with no SSH access. I might be able to do something with SVN.

    In the meantime, solved my script issue using cut to extract the filename:
    diff -qr oldbase newbase > basediff.txt
    grep 'differ' basediff.txt | cut -d ' ' -f 4 > grep1.txt
    for filename in `cat grep1.txt`
    do .....
    


Advertisement