ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Make this command better

    IT Discussion
    scripting bash sed rsync directory comparison
    3
    5
    704
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by

      While I use Linux (Feodra) daily, I do not use rsync and sed every day.

      I have a folder with two sub directories.
      Each subdirectory contains files form two different PBX systems.
      I wan to compare the filenames to get a list of things shared or only on a specific system.

      This works, but I assume a could do it better.

      rsync -n -a -i --delete newton/ edison/ | sed 's/*deleting  /only edison/g' | sed 's/>f+++++++++/only newton/g' | sed 's/>f.[.s]t....../on both    /g' | sed '/.d..t...... .\//d'
      

      Output of rsync without the sed` tweaks:

      [jbusch@lt-jared context_dump]$ rsync -n -a -i --delete newton/ edison/
      *deleting   context_ivrSNOW
      .d..t...... ./
      >f+++++++++ context_ata-outbound
      >f..t...... context_default
      >f.st...... context_main
      

      Output after sed

      only edison context_ivrSNOW
      only newton context_ata-outbound
      on both     context_defualt
      on both     context_main
      

      Explanation of the bits:
      List the diffrences: rsync -n -a -i --delete newton/ edison/
      Delete means only on Edison: sed 's/*deleting /only edison/g'
      Plus' mean only on Newton: 's/>f+++++++++/only newton/g'
      File on both with different size or timestamp: sed 's/>f.[.s]t....../on both /g'
      Just remove the empty directory line: sed '/.d..t...... .\//d'

      1 Reply Last reply Reply Quote 1
      • DustinB3403D
        DustinB3403
        last edited by

        What is this doing or not doing that you need it to do?

        JaredBuschJ 1 Reply Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch @DustinB3403
          last edited by

          @DustinB3403 said in Make this command better:

          What is this doing or not doing that you need it to do?

          @JaredBusch said in Make this command better:

          This works, but I assume a could do it better.

          .....

          DustinB3403D 1 Reply Last reply Reply Quote 0
          • DustinB3403D
            DustinB3403 @JaredBusch
            last edited by

            @JaredBusch said in Make this command better:

            @DustinB3403 said in Make this command better:

            What is this doing or not doing that you need it to do?

            @JaredBusch said in Make this command better:

            This works, but I assume a could do it better.

            .....

            Better is not a useful qualifier! Better how?!

            1 Reply Last reply Reply Quote 0
            • M
              manxam
              last edited by manxam

              @JaredBusch : I'm not certain if this fits the bill, but what about the "diff" command? Of course, this does nothing to sync the files but does offer a way to simply compare the directories.

              diff -rs manxam jaredbusch
              

              This will get you :

              Files /home/manxam/TEST and /home/jaredbusch/TEST are identical
              Only in /home/manxam: i_am_manxam
              Only in /home/jaredbusch: you_are_jared
              
              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post