1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/bash
- while getopts "n" options; do
- case $options in
- n ) DRYRUN="-n";;
- * ) echo 'Usage: unixify.sh FILES...'
- exit 1;;
- esac
- done
- shift $((OPTIND-1))
- for file in "$@"; do
-
- newfile=`rename -v $DRYRUN \
- "y/ /_/;
- s/[!?':\",\[\]()#]//g; "'
- s/&/and/g;
- y/A-Z/a-z/;
- s/\.\.\./_/g;
- s/_+/_/g;
- s/_(\.[^.]+$)/$1/;
- s/\.jpeg$/.jpg/' \
- "$file"`
- if [[ $DRYRUN != "" ]]; then
- if [[ $newfile != "" ]]; then
- echo $newfile
- fi
- continue
- fi
- if [[ $newfile =~ ' renamed as ' ]]; then
- file=${newfile/* renamed as /}
- fi
- if [[ $file =~ \.(gif|jpg|png)$ ]]; then
-
- mogrify -auto-orient $file
- elif [[ $file =~ \.doc$ ]]; then
-
- antiword $file > `basename $file .doc`.txt
- fi
- if [[ `file -b $file` =~ text,.*with\ CRLF ]]; then
-
- sed --in-place 's/\r//g' $file
- fi
- done
|