Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Script Dump

Name: Anonymous 2010-05-13 5:18

Hey /prog/, Just a place to dump useful shell/python/etc scripts

This one batch-renames file extentions in the current directory
extconv.sh
#!/bin/sh
###########################################
# ExtentionConverter
# Converts *.type1 files to *.type2 files
###########################################

##Extention Remover
#Voodo magic I stole
noExt() {
   echo $i | awk -F"." '{ for ( i=1; i<NF; i++) { printf "%s", $i; if ( i < NF - 1 ) { printf "%s", "." } } printf "\n" }'
}

##Args Check
if [ "$1" != "" ] && [ "$2" != "" ]; then
   echo "\nExtConvert -$1 to $2-"
else
   echo "\nExtConvert -help-"
   echo "Usage: `basename $0` <type1> <type2>"
   echo "This script converts all the files in the"
   echo " current directory that are of type 1 to type 2"
   echo "Eg: `basename $0` rar cbr"
   echo "This would convert all the files in the"
   echo " current directory from .rar to .cbr\n"
   exit 1
fi

##File Processing
for i in *.$1; do

   #There's some files to convert
   #Change old extention to new extention
   if [ "$i" != "*.$1" ]; then
      noext=$(noExt)
      echo "$i became $noext.$2"
      mv "$i" "$noext.$2"
     
   #No files to convert
   #Tell the user and exit
   else
      echo "No $1 Files to Convert"
   fi

done
echo ""
exit 0

Name: Anonymous 2010-05-13 5:20

Also, one for use by LaTeXfags; cleans the temp crap and the tilde-temp files recursive from where the file's run:

cleanup.sh
#!/bin/bash
#################################
# LaTeXcLeAnUp
# Deletes Unneeded LaTeX Files
#################################
if [ -n "$1" ]; then
   cd "$1"
else
   echo ""
   echo "LaTeXcLeAnUp : cleaning"
fi

for i in *; do
  
   # if dir, scan dir
   if [ -d "$i" ]; then
      if [ -n $1 ]; then
         "$0" "$i"
      else
         "$0" "$i"
      fi
  
   # if temp (~) crap, delete
   elif [[ "$i" == *~ ]]; then
      rm "$i"
  
   # if aux crap, delete
   elif [[ "$i" == *.aux ]]; then
      rm "$i"
  
   # if aux crap, delete
   elif [[ "$i" == *.log ]]; then
      rm "$i"
  
   # if aux crap, delete
   elif [[ "$i" == *.out ]]; then
      rm "$i"
  
   # if aux crap, delete
   elif [[ "$i" == *.toc ]]; then
      rm "$i"
   fi
done

if [ -n "$1" ]; then
   wait
else
   echo "LaTeXcLeAnUp : cleaned"
   echo ""
fi

exit 0

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List