1.Linux Shell intercepts the first 8 bits of a character variable
There are several ways to implement this:
- Expr substr "$a" 1 8
- echo $a |awk ' {print substr (, 1,8)} '
- Echo $a |cut-c1-8
- echo $
- Expr $a: ' \ (. \ \).
- echo $a |dd Bs=1 count=8 2>/dev/null
2. Intercept by the specified string
(1) The first method:
A string after the last string is truncated from left to right
${varible##*string}
A string after the first string is truncated from left to right
${varible#*string}
A string after the last string is intercepted from right to left
${varible%%string*}
A string after the first string is intercepted from right to left
${varible%string*}
"*" is just a wildcard can not
Take a look at the following example:
$ myvar=foodforthought.jpg$ echo ${myvar##*fo}rthought.jpg$ Echo ${myvar#*fo}odforthought.jpg
(2) The second method:
${VARIBLE:N1:N2}: Intercepts the variable varible the N2 character starting from N1, forming a substring. You can select specific substrings by using a different form of variable extension, depending on the specific character offset and length. Try entering the following line in bash:
$ exclaim=cowabunga$ echo ${exclaim:0:3}cow$ Echo ${exclaim:3:7}abunga
This form of string truncation is simple, with only a colon separated to specify the starting character and substring length.
3. Split according to the specified requirements:
3.1 For example, get a list of suffix ls
CD $FROM _dir
For i in ' ls E2c_all_*|awk ' {print '} '
Do
Echo $i
S_filename= "
echo "define param: $s _filename"
3.2 Getting row data
Cat $i | While Read line
Do
Va_line=${line}
headfix= ' expr substr ' $va _line "1 1 '
if [$headfix = "#"];then
3.3 Intercept the keyword, the field before the number, two times the field after the # number is intercepted
S_filename= ' echo $va _line|awk-f ', ' {print $} ' |awk-f ' # ' {print $} '
Content= ' echo $va _line|awk-f ', ' {print $} '
echo "FileName: $s _filename"
Touch $TO _dir$s_filename
echo $content >> $TO _dir$s_filename
Else
echo $va _line >> $TO _dir$s_filename
Fi
Done
3.4 After the append processing is finished, do the backup processing
MV ${i} ${back_dir}${i}
Done
Keywords in the shell intercept file