The method of string interception under shell

Source: Internet
Author: User
Tags first string

One of the first few instances of the Linux shell intercepting strings, the first 8 bits are intercepted:

The method is as follows: A=1234STERRERWRWRETW below

1.expr substr "$a" 1 8

           

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/82/E0/wKioL1djmGSz23i0AAATSvmp7h0082.png-wh_500x0-wm_3 -wmp_4-s_3381070801.png "style=" Float:none; "title=" HTP. PNG "alt=" wkiol1djmgsz23i0aaatsvmp7h0082.png-wh_50 "/>650) this.width=650; src=" http://s2.51cto.com/wyfs02/M00 /82/e0/wkiol1djmgsbymazaaapos5gdgg833.png-wh_500x0-wm_3-wmp_4-s_408133305.png "title=" HH.png "style=" Float:none; " alt= "Wkiol1djmgsbymazaaapos5gdgg833.png-wh_50"/>

2.echo $a |cut-c1-8

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/82/E0/wKioL1djnAmBNuA-AAAV4a793tU472.png-wh_500x0-wm_3 -wmp_4-s_4126771407.png "title=" Hh.png "alt=" Wkiol1djnambnua-aaav4a793tu472.png-wh_50 "/>

3..echo $a |dd Bs=1 count=8

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/82/E0/wKioL1djnqLw6kS5AAAsUDnEp8w262.png-wh_500x0-wm_3 -wmp_4-s_1254542455.png "title=" Hh.png "alt=" Wkiol1djnqlw6ks5aaasudnep8w262.png-wh_50 "/>

Two. Intercept by the specified string

1, the first method:

1> ${val##*string} (double #* intercept)

A string after the last string is truncated from left to right

Example: A= 123stringrwtw134string456

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/E2/wKiom1djpSXgREaHAAALwJJiomg680.png-wh_500x0-wm_3 -wmp_4-s_4065638307.png "title=" HTP. PNG "alt=" Wkiom1djpsxgreahaaalwjjiomg680.png-wh_50 "/>

2>${varible#*string} (single #* intercept)

from left to right a string after the first string is intercepted

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/82/E2/wKiom1djpbzBKJNwAAAOCPAcI1I904.png-wh_500x0-wm_3 -wmp_4-s_3654494428.png "title=" HTP. PNG "alt=" Wkiom1djpbzbkjnwaaaocpaci1i904.png-wh_50 "/>

3> ${val%%string*} ( double%* intercept )

To intercept the string before the last string from right to left

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/82/E1/wKioL1djp9TTYHWyAAAN1gzT2hk125.png-wh_500x0-wm_3 -wmp_4-s_2777975290.png "title=" client. PNG "alt=" Wkiol1djp9ttyhwyaaan1gzt2hk125.png-wh_50 "/>

4> ${val%string*} intercepts the string before the first string from right to left (single%* intercept)

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/E1/wKioL1djqBTz8D3-AAAPnyY9DlI472.png-wh_500x0-wm_3 -wmp_4-s_4141402123.png "title=" client. PNG "alt=" Wkiol1djqbtz8d3-aaapnyy9dli472.png-wh_50 "/>

2. The second method:

1>${val:n1:n2}: Intercept variable val from left N1 begins intercepting N2 strings. Note: string from 0 count

Continue to use the A variable above

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/82/E2/wKioL1djqhfjsWz3AAAOaaVWJQQ549.png-wh_500x0-wm_3 -wmp_4-s_630306009.png "title=" capture. PNG "alt=" Wkiol1djqhfjswz3aaaoaavwjqq549.png-wh_50 "/>

2>${VAL:0-N1:N2}: Intercepts the variable Val from the right start 0 to N1 between the string intercept n2. (from left to right when intercepting)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/E4/wKiom1djsHKih-arAAAaki58Qow893.png-wh_500x0-wm_3 -wmp_4-s_3018298947.png "title=" client. PNG "alt=" Wkiom1djshkih-araaaaki58qow893.png-wh_50 "/>

3>${VAL:0-N1}: Intercept variable val n1 A string from right start


650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/E3/wKioL1djthuDaXukAAAfKP7Qg3Q283.png-wh_500x0-wm_3 -wmp_4-s_3608931875.png "title=" client. PNG "alt=" Wkiol1djthudaxukaaafkp7qg3q283.png-wh_50 "/>

4>${VAL:N1} intercepts all strings after N1 start


650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/E4/wKiom1djtj_BlWOVAAAYigvS45M090.png-wh_500x0-wm_3 -wmp_4-s_3304349905.png "title=" client. PNG "alt=" Wkiom1djtj_blwovaaayigvs45m090.png-wh_50 "/>




This article is from the "Output Diamond pattern" blog, so be sure to keep this source http://10541571.blog.51cto.com/10531571/1790377

The method of string interception under shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.