Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Compare all files in directory, list filenames only

  • 03-03-2011 6:21pm
    #1
    Registered Users, Registered Users 2 Posts: 6,465 ✭✭✭


    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,465 ✭✭✭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