26 Ways to practice the substring of a Linux shell by taking variables

Source: Internet
Author: User

######### #20150419 ############################# #题目: Variable a= ' a/b/c ' how to intercept get c @@@@@@@@@@@@@@@@ From the operation and maintenance class 21 long wing finishing @@@@@@@@@@@@@@@@@@@[[email protected] shell]$ uname -r 2.6.32-504. El6.x86_64[[email protected] shell]$ cat /etc/redhat-release centos release  6.6  (Final) method one [[email protected] shell]$ echo  $a  | cut -c5c method two [[ email protected] shell]$ echo  $a  | tr  "a/b/"   "     "    # #四个空格     c    method Three [[email protected]  shell]$ echo  $a  | tr  "/"   "\ n" |tail -1c method four [[Email protected] shell ]$ echo  $a  | tr -d  ' a/b/' C method five [[Email protected] shell]$ echo   $a  | rev |head -c1c[[email protected] shell]$  method six [[email  protected] shell]$ echo  $a  | rEv |cut -c1c method Seven [[email protected] shell]$ echo  $a  | grep -o  "[a-z]$" C method eight [[email protected] shell]$ echo  $a  | grep -o  "[^ab/]" C Method Nine [ [email protected] shell]$ echo  $a  | sed   ' s#.*/## '  c method 10  [[ email protected] shell]$ echo  $a  | sed  ' y#a/b/#    # '   # #四个空格     c Method 11 [[email protected] shell]$ echo  $a  |  sed -r  ' s# .... (.) #\1# '  c method 12 [[email protected] shell]$ echo  $a  | sed -r  ' s#.* ([A-Z ]$) #\1# ' C method 13 [[email protected] shell]$ echo  $a  | awk -F/  ' {print   $NF} ' C method 14 [[email protected] shell]$ echo  $a  | awk  ' {gsub (". * *", "", $ );p Rint} ' C method 15 [[email protected] shell]$ echo  $a  | awk  ' {split ($0,array, "/");p Rint array[3]} ' C method 16 [[email protected] shell]$ echo  $a  | awk   ' {split ($0,array, "a/b/");p rint array[2]} ' C method 17 [[email protected] shell]$ echo $ a | awk  ' {sub (/[^c]+/, "");p Rint} ' C method 18 [[email protected] shell]$ echo  $a  | awk  ' {gsub ("/", "\ n");p rint $3} ' C method 19 [[Email protected] shell]$ echo   $a  | awk  ' {print substr ($0,5,1)  } ' C method 20 [[email protected] shell]$  echo  $a  | awk   ' begin{rs= ' [/\n] "}nr==3 ' C method 21 [[Email protected] shell ]$ echo  $a |cut -d/ -f3   # #上海-Yi Xiaoyi nc method 22 [[Email protected] shell] $ echo ${a:4}# #北京-Xu Fu C method 23 [[email protected] shell]$ echo ${a##*/}## BEIJING-Xu Fu C method 24 [[email protected] shell]$ echo  $a  |tr  "/"   "\ n" |awk  ' nr==3 ' C method 25 [[EMAIL PROTECTED]&NBsp;shell]$ echo ${a:4:1}# #上海-Yi Xiaoyi C Method 26 [[Email protected] shell]$ echo ${a# #a/b/}   # #北京-Liu Xiaotao C


26 Ways to practice the substring of a Linux shell by taking variables

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.