User Tools

Site Tools


linux:bashscriptexamples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:bashscriptexamples [2014/05/18 15:11] adminlinux:bashscriptexamples [2015/11/12 14:03] (current) – removed admin
Line 1: Line 1:
-====== Bash Script Examples ====== 
-===== Actual scripts to process text ===== 
-==== Find files that contain the text with for ==== 
-<code bash>for i in `find 20090820R1_YN -name '*.xml'`; do text=`cat $i | grep "9848"`; if [$text -eq ""]; then text=""; else echo "-------------------------$i:"; echo $text; fi  done 
-</code> 
-<code bash>for i in `find 20091128Q1_YN -name '*.xml'`; do text=`cat $i | grep 'username='`; if [$text -eq ""]; then text=""; else echo "-------------------------$i:"; echo $text; fi  done 
-</code> 
  
-==== readline with while ==== 
-=== example1 === 
-<code bash> 
-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 
-</code> 
-=== example2 === 
-<code bash> 
-#!/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 
-</code> 
-=== example3 === 
-<code bash> 
-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 
-</code> 
- 
-==== check file exists ==== 
-<code bash>if [  -f ./flash/giai-tri/giaitri_347.swf ]; then echo "1"; else echo "2";  fi;</code> 
-<code bash>for i in `cat listgames.txt `; do filename=`find . -name "$i.swf"`;if [ ! -f $filename ]; then echo "$filename"; fi; done</code> 
-<code bash>for i in `cat listgames.txt `; do filename=`find . -name "${i}_image.jpg"`;if [ ! -f $filename ]; then echo "$filename"; fi; done</code> 
-==== change text ==== 
-=== example1 === 
-<code bash>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 
-</code> 
-=== example2 === 
-<code bash>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 
-</code> 
-==== get text in flash ==== 
-Create svn.txt 
-<code> 
-*.svn 
-*.settings 
-*.project 
-*.buildpath 
-*.swf 
-*.fla 
-*.as 
-*.xml 
-*.jpg 
-*.png 
-*.PNG 
-*.psd 
-*.db 
-*.bak 
-*.mp3 
-</code> 
-  * string:<code bash> 
-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 
-</code> 
-  * int:<code bash> 
-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 
-</code> 
-  * byte:<code bash> 
-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 
-</code> 
-  * short:<code bash> 
-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 
-</code> 
-  * <code bash> 
-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 
-</code> 
-  * <code bash> 
-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 
-</code> 
-  * <code bash> 
-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 
-</code> 
-==== update gameloader and LoadInterface ==== 
-<code bash> 
-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 
-</code> 
- 
-<code bash> 
-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 
-</code> 
linux/bashscriptexamples.1400425861.txt.gz · Last modified: 2022/10/29 16:15 (external edit)