aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2016-01-25 20:48:14 +0100
committerVG <vg@devys.org>2016-01-25 20:48:14 +0100
commit552252a172eebe758f2c87131c4da33c6a3cc4d5 (patch)
treed676340f55036562f9e71c36bdaca2e58db578da
parentac5deefcfba8a5e29634af50cd43941d81b051c5 (diff)
downloadbulkrename-552252a172eebe758f2c87131c4da33c6a3cc4d5.tar.gz
bulkrename-552252a172eebe758f2c87131c4da33c6a3cc4d5.tar.bz2
bulkrename-552252a172eebe758f2c87131c4da33c6a3cc4d5.zip
Optimize renaming process from a loop to pipes
-rwxr-xr-xbulkrename12
1 files changed, 6 insertions, 6 deletions
diff --git a/bulkrename b/bulkrename
index 3df3b4b..88cb363 100755
--- a/bulkrename
+++ b/bulkrename
@@ -27,13 +27,13 @@ fi
sed -i -- 's/\([\\"$`]\)/\\\1/g;' "${namebase}.1" "${namebase}.2"
-paste -d "\n" "${namebase}.1" "${namebase}.2" | while read -r input ; do
- read -r output
+(echo '# Please review/modify this script or empty it to do nothing' \
+ ; paste -d "\n" -- "${namebase}.1" "${namebase}.2" \
+ | uniq -c \
+ | sed -n 's/^ *1 \(.*\)$/"\1"/p' \
+ | xargs -d"\n" -L2 echo 'mv -i --') \
+ > "${namebase}.sh"
- if [ "$input" != "$output" ] ; then
- echo "mv -- '$input' '$output'"
- fi
-done > "${namebase}.sh"
if [ "$(stat --printf="%s" "${namebase}.sh")" -ne 0 ] ; then
"$EDITOR" "${namebase}.sh"