Created
February 8, 2018 05:05
-
-
Save tmasjc/7c2913960d9d40594d01ad7e00b69331 to your computer and use it in GitHub Desktop.
Rename multiple files at once using regex. #bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript --vanilla | |
args <- commandArgs(trailingOnly = TRUE) | |
# List all files | |
items <- list.files(path = ".") | |
# See which matches argument (regex) | |
old <- items[grep(items, pattern = args[1])] | |
# What to replace to? | |
new <- gsub(pattern = args[1], replacement = args[2], x = old) | |
# Replace those matches | |
file.rename(old, new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment