User Tools

Site Tools


linux:bashshell

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:bashshell [2016/01/15 05:01] – [integer comparison] adminlinux:bashshell [2022/10/29 16:15] (current) – external edit 127.0.0.1
Line 315: Line 315:
 </code> </code>
 ==== Find files that contain the text ==== ==== Find files that contain the text ====
 +  * Simple<code bash>
 +grep -rnw . -e "Begin Facebook Code"
 +</code>
 +  * Custom find with regular expression<code bash>
 +grep -rnw . -e 'mongo.*'
 +</code>
 +==== Find files that file name length > 29 ====
 <code bash> <code bash>
-grep -rnw babyshopvn -e "Begin Facebook Code"+for i in `ls -1`;do sub_i=(`echo $i|cut -d'-' -f 1`);lensub_i=${#sub_i}; if [ $lensub_i -ge 29 ]; then echo $sub_i;echo $i; fi  done
 </code> </code>
 ==== Manipulating String ==== ==== Manipulating String ====
 +refer: http://tldp.org/LDP/abs/html/string-manipulation.html 
 +  * String length: **${#string}**:<code bash> 
 +str="First String"; echo ${#str} 
 +</code>output:<code> 
 +12 
 +</code> 
 +  * Replace String:<code>${string//substring/replacement}</code>Example:<code bash> 
 +str="First String"; echo ${str//First/Second} 
 +</code>output:<code> 
 +Second String 
 +</code> 
 +==== update array to file ==== 
 +Below is array configs.txt:<code> 
 +c1 = 0,4,5,8,9,12,13,16,17,19,22,21,45,2,3,6,7,10,11,14,15,20,1,23,44,50,26,27,28,29,30,31,32,33,34,35,38,49,47,18,36,37,24,39,40,41,42,43,46,48,25,51 
 +c2 = 51,4,5,8,9,12,13,16,17,25,22,21,45,2,3,6,7,10,11,14,15,20,1,23,44,50,26,27,28,29,30,31,32,33,34,35,38,49,47,18,36,37,24,39,40,0,42,43,46,48,19,41 
 +c3 = 26,27,33,34,8,9,12,13,40,41,0,30,31,2,3,6,7,10,11,14,15,20,21,23,44,50,45,1,28,29,32,19,22,4,5,35,38,49,47,18,36,37,24,39,16,17,42,43,46,48,25,51 
 +</code> 
 +update array to files: 
 +<code bash> 
 +index=0;for i in `cat configs.txt | awk '{print $3}'`; do let "index = $index + 1";echo $i > c$index.txt; done 
 +</code>
linux/bashshell.1452834115.txt.gz · Last modified: 2022/10/29 16:15 (external edit)