Results 1 to 3 of 3

Thread: rsync script to rewrite suffix - BASH, awk, sed, perl?

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    my(@HOME, -$NJ)
    Beans
    296
    Distro
    Ubuntu 14.04 Trusty Tahr

    rsync script to rewrite suffix - BASH, awk, sed, perl?

    trying to write up a script to put the suffix back.
    heres what I have but can't get it to do anything
    would like it to be name.date.suffix

    Code:
        rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~"--bwlimit=1024/mymounts/test1/ /mymounts/test2/
    Code:
    while IFS=. read -r -u 9-d '' name suffix date tildedo    mv "${name}.${suffix}.${date}.~""${name}.${date}.${suffix}"done9<<(find .-type f -name "*.~"-print0)
    Code:
        rsync
    Code:
    -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~"--bwlimit=1024/mymounts/test2/ /mymounts/test1/
    Code:
    while IFS=. read -r -u 9-d '' name suffix date tildedo    mv "${name}.${suffix}.${date}.~""${name}.${date}.${suffix}"done9<<(find .-type f -name "*.~"-print0)
    still not rewriting as I would like, got file renamed as "test1.txt.20130320 95325.~"
    Thanks in advance,

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,790
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: rsync script to rewrite suffix - BASH, awk, sed, perl?

    Hi alienprdkt.

    There are several syntax errors on your commands (lines split, commands joined together).

    My guess is it was a copy/paste problem.

    Could you edit your post so we can take a look at your actual scripts?

    Kind Regards.

  3. #3
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: rsync script to rewrite suffix - BASH, awk, sed, perl?

    Besides the copy-paste problem, there's another: your code presumes that files have only one suffix. How would you handle file.tar.gz? Also note that since the find is executed on the current directory (.), it will prepend ./ to each file name and the first variable you're reading into ($name) will be assigned empty value.

    Try
    Code:
    find -type -f -name '.*.*.~' -exec rename -vn 's:(\.[^./]+)(\.[^./]+)\.~$:$2$1:' {} +
    n is there for testing purposes. When you're sure the command does what you want, remove n and rerun the command to do the actual renaming.

    BTW, why would you use space-padded hours (%k) in the date format expression?
    Last edited by schragge; April 9th, 2013 at 10:47 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •