reorganization, and output filename for SimpleWeb
This commit is contained in:
37
files/mvregex
Executable file
37
files/mvregex
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
function helpexit() {
|
||||
echo rename files in current folder replacing arg1 with arg2.
|
||||
echo '-n for match non ascii, replace with arg2'
|
||||
exit
|
||||
}
|
||||
|
||||
IFS=$'\n'
|
||||
[[ -z "$1" ]] && helpexit
|
||||
[[ "$1" = "-h" ]] && helpexit
|
||||
|
||||
POSTPROC="sed 's, , -> ,'"
|
||||
which ncsv &>/dev/null && POSTPROC="ncsv -c"
|
||||
c=0
|
||||
if [ "$1" = "-n" ]
|
||||
then for file in $( ls | grep -P "[\x80-\xFF]" )
|
||||
do echo "$file" '->' "$( echo $file | tr -d \\n\\r | tr -c [:print:] '\000' | sed s/'\x0'/"$2"/g )"
|
||||
c=$(( $c + 1 ))
|
||||
done
|
||||
echo $c' matches. Sure?'
|
||||
read i
|
||||
for file in $( ls | grep -P "[\x80-\xFF]" )
|
||||
do mv -iv -- "$file" "$( echo $file | tr -d \\n\\r | tr -c [:print:] '\000' | sed s/'\x0'/"$2"/g )"
|
||||
done
|
||||
exit
|
||||
fi
|
||||
(
|
||||
echo -e "Matching\tReplaced"
|
||||
for file in $( ls | grep -- "$1" )
|
||||
do echo -e "$file"\\t"$( echo $file | sed s/"$1"/"$2"/g )"
|
||||
done ) | eval $POSTPROC | grep --color=always -E "$1|$"
|
||||
echo 'Sure?'
|
||||
read i
|
||||
for file in $( ls | grep -- "$1" )
|
||||
do mv -iv -- "$file" "$( echo $file | sed s/"$1"/"$2"/g )"
|
||||
done
|
||||
Reference in New Issue
Block a user