BreadCrumbs: Bash Scripts

Bash Scripts

From Luke Jackson

(Difference between revisions)
Jump to: navigation, search
Revision as of 20:29, 10 May 2009 (edit)
Ljackson (Talk | contribs)
(Count Files in Subdirectories)
← Previous diff
Revision as of 20:32, 10 May 2009 (edit)
Ljackson (Talk | contribs)
(Echo Random Word X Times)
Next diff →
Line 73: Line 73:
== Echo Random Word X Times == == Echo Random Word X Times ==
-for ((i=1;i<=555;i+=1)); do printf "`sed \`perl -e "print int rand(99999)"\`"q;d" /usr/share/dict/words` "; done+ for ((i=1;i<=555;i+=1)); do printf "`sed \`perl -e "print int rand(99999)"\`"q;d" /usr/share/dict/words` "; done
[[Category:Linux]] [[Category:Linux]]
[[Category:Mac OS X]] [[Category:Mac OS X]]

Revision as of 20:32, 10 May 2009

Contents

Simple Wget Loop

alpha=( aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz )

alpha_count=${#alpha[*]}

x=0

while [ "$x" -lt "$alpha_count" ]
do    # List all the elements in the array.
  wget -O ${alpha[$x]}.wav http://german.about.com/library/media/sound/${alpha[$x]}.wav
  sleep 1
  let "x = $x + 1"
done

Conditional Device Check & Image Upload (Mac OS X)

#!/bin/bash

CAMSTAT=`/usr/sbin/system_profiler SPUSBDataType | awk '{$1=$1;print}' | grep WebCam | cut -c 1-6`

if [ "$CAMSTAT" = "WebCam" ]; then

 # Create History Image
 echo Make History
 scp -P 2222 ~/m31uk3.jpg me@server.com:/www/server.com/htdocs/webcam/history/m31uk3_`date +%s`.jpg

 # Update Webcam
 echo Take a Picture
 scp -P 2222 ~/m31uk3.jpg me@server.com:/www/server.com/htdocs/webcam/

else
 echo No Cam Connected!
fi

Move Files Based On Date Name

for ARG in $*
do
  PICPATH=`echo $ARG | cut -d_ -f 2 | cut -d. -f 1 | utimecam`
#  echo $PICPATH
  mv -v $ARG $PICPATH/$ARG
#  sleep 1
done

Replace Multiple Strings, Words, Regular Expressions in Multiple Files from Terminal

find . -name '*.svg' | xargs -IX grep -E '12:(04|05|08|11|16|21|22|33|35|36|46) am 01.20.09' X | sort | wc -l
for i in `find . -name '*.svg' | xargs -IX grep -lE '12:(04|05|08|11|16|21|22|33|35|36|46) am 01.20.09' X` ; do
 amcount=${#i}
 extension="${i##*.}"
 newname="${i%?.*}"
 cat "$i" | sed -e 's/12:04 am 01.20.09/12:04 pm 01.20.09/' -e 's/12:05 am 01.20.09/12:05 pm 01.20.09/' -e 's/12:08 am 01.20.09/12:08 pm 01.20.09/' -e 's/12:11 am 01.20.09/12:11 pm 01.20.09/' -e 's/12:16 am 01.20.09/12:16 pm 01.20.09/' -e 's/12:21 am 01.20.09/12:21 pm 01.20.09/' -e 's/12:22 am 01.20.09/12:22 pm 01.20.09/' -e 's/12:33 am 01.20.09/12:33 pm 01.20.09/' -e 's/12:35 am 01.20.09/12:35 pm 01.20.09/' -e 's/12:36 am 01.20.09/12:36 pm 01.20.09/' -e 's/12:46 am 01.20.09/12:46 pm 01.20.09/' > "$i".fix.svg
 echo "$i" of "$amcount"
diff "$i" "$i".fix.svg
wc -l "$i"
wc -l "$i".fix.svg
mv "$i".fix.svg "$i"
done

Count Files in Subdirectories

for i in `ls -1d */pixel/*trans*`; do echo -e $i = `find -E $i -regex '.*(.png|.jpg)' | wc -l`; done

Echo Random Word X Times

for ((i=1;i<=555;i+=1)); do printf "`sed \`perl -e "print int rand(99999)"\`"q;d" /usr/share/dict/words` "; done
Personal tools