Scripting
- Here I'll collect some of the scripts I wrote during the past years to make life easier. I mainly use bash command line scripts, but I'll also include some SciLab, Perl, PHP, Matlab, etc. etc.
Show all EPS files in a directory
- Very handy script I wrote to have somewhere in a PATH located directory: showalleps.sh
a=`ls | grep eps`;for b in $a; do echo " gv $b & ">>alleps.sh; done; #chmod 765 alleps.sh; `sh ./alleps.sh`; rm alleps.sh;Don't forget to make it executable:
#chmod 765 showalleps.sh
Convert EPS into cropped PDF
- To convert just the eps image, and not the white margins around into a pdf use the following under linux:
ps2pdf -dEPSCrop file.eps file.pdf
#!/bin/bash set -o posix echo "all .eps files will be converted into .pdf"; # Find all eps files in the current directory, and convert them list=`ls | grep eps`; for each in $list; do name=${each%%????}; ps2pdf -dEPSCrop $name.eps $name.pdf done; # Now combine all pdf files into one pdf file: gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH *.pdf echo "Done!"; # Automatically show the results `acroread combinedpdf.pdf &`
Convert PDF into a JPEG image
- To convert a pdf (image) into a jpg image do the following under linux. Density is in Pixels per Inch.
convert -quality 100 -density 600 FooIN.pdf FooOUT.jpg
#!/bin/bash set -o posix echo "all .pdf files will be converted into .jpg"; list=`ls | grep pdf`; for each in $list; do name=${each%%????}; convert -quality 100 -density 600 $name.pdf $name.jpg done; echo "Done!";
Change Multiple Filenames
- Very handy script I wrote to have somewhere in a PATH located directory: chname.sh
#!/bin/bash set -o posix # $1 is the value to look up, $2 is the one to replace it with # eg chname.sh 103 89 old=$1; new=$2; list=`ls | grep $old`; for each in $list; do eachnew=`echo $each | sed s/$old/$new/g`; mv "$each" "$eachnew"; done; echo "Moved all $old to $new.";Simple to use, just write:
#chname.sh 103 89and all the files with the number 103 in the filename will be changed into files with 89 in the filename instead.
Convert from upper to lower case in multiple filenames
- Very handy script (someone else wrote, sorry I don't know where I got it from) to have somewhere in a PATH located directory: upper2lower.sh
#!/bin/bash # upper2lower - convert all files in a directory from upper # to lower case filenames and replace spaces with _ for f in *; do # turn all spaces into underscores mv \"$f\" `echo \"$f\" | tr [:space:] _` done for g in *; do # make all characters lowercase mv $g `echo $g | tr A-Z a-z` done # EOF