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
Last revisionBoth sides next revision
linux:bashshell [2016/01/15 06:19] – [Manipulating String] adminlinux:bashshell [2021/05/24 15:18] – [Find files that contain the text] admin
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>   * String length: **${#string}**:<code bash>
 str="First String"; echo ${#str} str="First String"; echo ${#str}
Line 328: Line 336:
 </code>output:<code> </code>output:<code>
 Second String 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> </code>
linux/bashshell.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1