其中有一些是我寫的,其它都是彙總shell羣裏面的大牛寫的,你們有更好的方法也能夠提出來。sql
要求:把第一個數字和後面的「/」去掉shell
- [root@yunwei14 scripts]# cat StringCut.txt
- 123/
- 456/
- 789/
腳本實例:ide
- [root@yunwei14 scripts]# sed 's/^.//g;s/\///g' StringCut.txt
- 23
- 56
- 89
- [root@yunwei14 scripts]# cat StringCut.txt |cut -c 2-3
- 23
- 56
- 89
- [root@yunwei14 scripts]# cat StringCut.txt |while read String;do echo ${String:1:2};done
- 23
- 56
- 89
- [root@yunwei14 scripts]# grep -oP '(?<=.).*(?=/)' StringCut.txt
- 23
- 56
- 89
- [root@yunwei14 scripts]# for i in $(cat StringCut.txt);do expr substr "$i" 2 2; done
- 23
- 56
- 89
- [root@yunwei14 scripts]# awk 'sub("^.","")sub("/",""){print $0}' StringCut.txt
- 23
- 56
- 89
- [root@yunwei14 scripts]# awk 'BEGIN{FS=OFS=""}NF=3,sub(/^./,"")' StringCut.txt
- 23
- 56
- 89
- [root@yunwei14 scripts]# awk '{print substr($0,2,2)}' StringCut.txt
- 23
- 56
- 89
- [root@yunwei14 scripts]# awk -vFS='/' '$1=substr($1,2)' StringCut.txt
- 23
- 56
- 89
- [root@yunwei14 scripts]# awk -F '/' '{print substr ($1,2,3)}' StringCut.txt
- 23
- 56
- 89