Skip to main content
added 1 character in body
Source Link
NickD
  • 3k
  • 1
  • 14
  • 23

If this is a one-off, I find the following process to be the best fit between convenience and robustness:

  • Use ls with a pattern to select the files that you want and redirect the output to a file (the pattern is just an example, but it is not critical because of the next step):

    ls member_net.*.control > file.list

  • Edit file.list in your favorite editor: get rid of any files that you don't want to change (that's why the pattern above is not critical); make sure that it includes all the files that you want to change, adding any missing ones by hand if necessary; change each line from xxx to mv xxx XXX where XXX is just like xxx but with the modified date. This step depends on your editor, but can also be done by using sed on the original file and paste to paste the files together:

    sed 's/2017-04-20/2017-04-21/g' file.list > newfile.list

    paste file.list newfile.list > bothfiles.list

    sed 's/^/mv /' bothfiles.list > commands.list

  • You now should have a file commands.list that contains command lines of the form

    mv OLDNAME NEWNAME

  • Check it carefully to make sure each command line is correct and complete.

  • Then you can execute the commands by piping the file into your shell:

    cat commands.list | bash

What I find attractive is that I can check the file and make sure that it is exactly right and then without touching it at all execute all the commandcommands in it and be sure that it will do the right thing.

This is not as general as writing a shell script, but it is often a useful technique to remember.

If this is a one-off, I find the following process to be the best fit between convenience and robustness:

  • Use ls with a pattern to select the files that you want and redirect the output to a file (the pattern is just an example, but it is not critical because of the next step):

    ls member_net.*.control > file.list

  • Edit file.list in your favorite editor: get rid of any files that you don't want to change (that's why the pattern above is not critical); make sure that it includes all the files that you want to change, adding any missing ones by hand if necessary; change each line from xxx to mv xxx XXX where XXX is just like xxx but with the modified date. This step depends on your editor, but can also be done by using sed on the original file and paste to paste the files together:

    sed 's/2017-04-20/2017-04-21/g' file.list > newfile.list

    paste file.list newfile.list > bothfiles.list

    sed 's/^/mv /' bothfiles.list > commands.list

  • You now should have a file commands.list that contains command lines of the form

    mv OLDNAME NEWNAME

  • Check it carefully to make sure each command line is correct and complete.

  • Then you can execute the commands by piping the file into your shell:

    cat commands.list | bash

What I find attractive is that I can check the file and make sure that it is exactly right and then without touching it at all execute all the command in it and be sure that it will do the right thing.

This is not as general as writing a shell script, but it is often a useful technique to remember.

If this is a one-off, I find the following process to be the best fit between convenience and robustness:

  • Use ls with a pattern to select the files that you want and redirect the output to a file (the pattern is just an example, but it is not critical because of the next step):

    ls member_net.*.control > file.list

  • Edit file.list in your favorite editor: get rid of any files that you don't want to change (that's why the pattern above is not critical); make sure that it includes all the files that you want to change, adding any missing ones by hand if necessary; change each line from xxx to mv xxx XXX where XXX is just like xxx but with the modified date. This step depends on your editor, but can also be done by using sed on the original file and paste to paste the files together:

    sed 's/2017-04-20/2017-04-21/g' file.list > newfile.list

    paste file.list newfile.list > bothfiles.list

    sed 's/^/mv /' bothfiles.list > commands.list

  • You now should have a file commands.list that contains command lines of the form

    mv OLDNAME NEWNAME

  • Check it carefully to make sure each command line is correct and complete.

  • Then you can execute the commands by piping the file into your shell:

    cat commands.list | bash

What I find attractive is that I can check the file and make sure that it is exactly right and then without touching it at all execute all the commands in it and be sure that it will do the right thing.

This is not as general as writing a shell script, but it is often a useful technique to remember.

Source Link
NickD
  • 3k
  • 1
  • 14
  • 23

If this is a one-off, I find the following process to be the best fit between convenience and robustness:

  • Use ls with a pattern to select the files that you want and redirect the output to a file (the pattern is just an example, but it is not critical because of the next step):

    ls member_net.*.control > file.list

  • Edit file.list in your favorite editor: get rid of any files that you don't want to change (that's why the pattern above is not critical); make sure that it includes all the files that you want to change, adding any missing ones by hand if necessary; change each line from xxx to mv xxx XXX where XXX is just like xxx but with the modified date. This step depends on your editor, but can also be done by using sed on the original file and paste to paste the files together:

    sed 's/2017-04-20/2017-04-21/g' file.list > newfile.list

    paste file.list newfile.list > bothfiles.list

    sed 's/^/mv /' bothfiles.list > commands.list

  • You now should have a file commands.list that contains command lines of the form

    mv OLDNAME NEWNAME

  • Check it carefully to make sure each command line is correct and complete.

  • Then you can execute the commands by piping the file into your shell:

    cat commands.list | bash

What I find attractive is that I can check the file and make sure that it is exactly right and then without touching it at all execute all the command in it and be sure that it will do the right thing.

This is not as general as writing a shell script, but it is often a useful technique to remember.