其中有一些是我写的,其它都是汇总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