User Tools

Site Tools


linux:bashscriptexamples

This is an old revision of the document!


Bash Script Examples

Actual scripts to process text

Find files that contain the text with for

grep -rnw babyshopvn -e "Begin Facebook Code"

readline with while

example1

while read line; do username=`echo $line | awk '{print $1}'`;serverid=`echo $line | awk '{print $2}'`; echo $username,$serverid; mysql -uzf_9thien -p'.7#:qyJ&$&>bsU83r/#j[=yC' zf_9thien <<< "update fastreg set server_id='$serverid' where username='$username' limit 1;"; done < /tmp/a1.txt

example2

#!/bin/bash
if [ "aa$1" = "aa" ]; then
      date=`date +%Y_%m_%d`
else
      date=$1
fi
echo $date
while read line; do username=`echo $line | awk '{print $5}'`;serverid=`echo $line | awk '{print $7}'`;echo $username,$serverid;mysql -uzf_9thien -p'.7#:qyJ&$&>bsU83r/#j[=yC' zf_9thien <<< "update fastreg set server_id='$serverid' where username='$username' limit 1;"; done < /web/dangkynhanh.9thien.com/public/logs/GAMELOGIN_$date.log

example3

while read line; do trans_id=`echo $line | awk -F',' '{print $1}'`;username=`echo $line | awk -F',' '{print $2}'`; pay_transid=`cat /web/intwspay.onec.com/public/logs/gold/confirm/gold_confirm_2012_11_* | grep $trans_id | grep 'status: 1' | cut -d':' -f6 | cut -d' ' -f1`; echo "$trans_id,$username,$pay_transid"; done < log_gold_soha.csv

check file exists

if [  -f ./flash/giai-tri/giaitri_347.swf ]; then echo "1"; else echo "2";  fi;
for i in `cat listgames.txt `; do filename=`find . -name "$i.swf"`;if [ ! -f $filename ]; then echo "$filename"; fi; done
for i in `cat listgames.txt `; do filename=`find . -name "${i}_image.jpg"`;if [ ! -f $filename ]; then echo "$filename"; fi; done

change text

example1

while read line; do  i1=`echo $line | cut -d';' -f1`;i2=`echo $line | cut -d';' -f2`;excute=`echo "/bin/sed --in-place 's/\"${i1}\"/\"${i2}\"/"\' MainTimeline1.as`;eval $excute; done < listname1.txt

example2

while read line; do  i1=`echo $line | cut -d';' -f1`;i2=`echo $line | cut -d';' -f2`;excute=`echo "/bin/sed --in-place 's/\"${i1}\"/\"${i2}\"/"\' MainTimeline1.as`;eval $excute; done < listdesc1.txt

get text in flash

Create svn.txt

*.svn
*.settings
*.project
*.buildpath
*.swf
*.fla
*.as
*.xml
*.jpg
*.png
*.PNG
*.psd
*.db
*.bak
*.mp3
  • string:
    for i in `find . -name '*.swf'`;do rm -f ${i}_str.txt; touch ${i}_str.txt; done
    for i in `find . -name '*.swf'`;do /usr/local/bin/swfdump -a $i | grep pushstr | awk -F' ' '{print $5}' > ${i}_str.txt; done
  • int:
    for i in `find . -name '*.swf'`;do rm -f ${i}_int.txt; touch ${i}_int.txt; done
    for i in `find . -name '*.swf'`;do /usr/local/bin/swfdump -a $i | grep pushint | awk -F' ' '{print $5}' > ${i}_int.txt; done
  • byte:
    for i in `find . -name '*.swf'`;do rm -f ${i}_byte.txt; touch ${i}_byte.txt; done
    for i in `find . -name '*.swf'`;do /usr/local/bin/swfdump -a $i | grep pushbyte | awk -F' ' '{prbyte $5}' > ${i}_byte.txt; done
  • short:
    for i in `find . -name '*.swf'`;do rm -f ${i}_short.txt; touch ${i}_short.txt; done
    for i in `find . -name '*.swf'`;do /usr/local/bin/swfdump -a $i | grep pushshort | awk -F' ' '{prshort $5}' > ${i}_short.txt; done
  • for i in `find . -name '*.swf'`;do /usr/local/bin/swfdump -a $i > ${i}_as.txt; done
    rsync -avz --exclude-from=/home/anhvc/svn.txt  /web/9k/resource/ /home/anhvc/9k/code9k/
    for i in `find . -name 'Config.xml.txt'`; do rm -f $i; done
  • for i in `find . -name '*.swf'`;do /usr/local/bin/swfdump -t $i | grep DEFINETEXT > ${i}.txt;/usr/local/bin/swfdump -a $i | grep DEFINEEDITTEXT >> ${i}.txt;/usr/local/bin/swfdump -a $i | grep pushstr >> ${i}.txt; done
    rsync -avz --exclude-from=/home/anhvc/svn.txt  /web/9k/resource/ /home/anhvc/9k/texts/
    for i in `find . -name 'Config.xml.txt'`; do rm -f $i; done
  • for i in `find . -name '*.txt'`; do  du -sh $i | grep "0" | grep -v "K"; done > listremove.txt
    for i in `cat listremove.txt | cut -d'.' -f2-`; do rm -f /home/anhvc/9k/$i; done
    for i in `find . -name '*.txt'`; do rm -f $i; done

update gameloader and LoadInterface

while read line; do  i1=`echo $line | cut -d';' -f1`;i2=`echo $line | cut -d';' -f2`;for i in `find GameLoader-0 -name '*.*'`; do  excute=`echo "cat  $i | grep -i '$i1' | wc -l"`;echo $i1;eval $excute; done; done < gameloadertext.txt > checkfound.txt
while read line; do  i1=`echo $line | cut -d';' -f1`;i2=`echo $line | cut -d';' -f2`;for i in `find GameLoader-0 -name '*.*'`; do  excute=`echo "/bin/sed --in-place 's/${i1}/${i2}/ig"\' $i`;echo $i1;eval $excute; done; done < gameloadertext.txt
while read line; do  i1=`echo $line | cut -d';' -f1`;i2=`echo $line | cut -d';' -f2`;for i in `find LoadInterface-0 -name '*.*'`; do  excute=`echo "cat  $i | grep -i '$i1' | wc -l"`;echo $i1;eval $excute; done; done < loadinterfacetext.txt > checkfound.txt
while read line; do  i1=`echo $line | cut -d';' -f1`;i2=`echo $line | cut -d';' -f2`;for i in `find LoadInterface-0-update -name '*.*'`; do  excute=`echo "/bin/sed --in-place 's/${i1}/${i2}/ig"\' $i`;echo $i1;eval $excute; done; done < loadinterfacetext.txt
linux/bashscriptexamples.1437913440.txt.gz ยท Last modified: 2022/10/29 16:15 (external edit)