###%%%%%%%%%%脚本的用法:

 ##准备测试文件:

[root@zabbix-agent opt]# while read line ;do echo ${line%% *};done < stu.txt

01 oldboy 18
02 lidao 17
03 baojewery 66
04 happyday 9
05 oldcao 99

##获取文件中的序号::::%从右边向左边删除:
[root@zabbix-agent opt]# while read line ;do echo ${line%% *};done < stu.txt
01
02
03
04
05
[root@zabbix-agent opt]# while read line ;
> do
> echo ${line%% *}                 ###########直到删除右边的空格为止
> done < stu.txt
01
02
03
04
05

 

 #######“#”特殊符号从左向右删除::::

[root@zabbix-agent opt]# while read line; do echo ${line##*x}; done < stu.txt
18
17
66
9
99
[root@zabbix-agent opt]#
[root@zabbix-agent opt]#
[root@zabbix-agent opt]#
[root@zabbix-agent opt]#
[root@zabbix-agent opt]#
[root@zabbix-agent opt]# while read line; do echo ${line##x}; done < stu.txt^C
[root@zabbix-agent opt]# cat stu.txt
01 oldboyx18
02 lidaox17
03 baojeweryx66
04 happydayx9
05 oldcaox99

posted @ 2023-11-22 13:41  往事已成昨天  阅读(256)  评论(0编辑  收藏  举报