linux系统中如何删除文件中的第几个字符

1、测试数据

[root@PC3 test]# cat b.txt
sfg3
dg2k

 

2、删除第三个字符,sed删除

[root@PC3 test]# cat b.txt
sfg3
dg2k
[root@PC3 test]# sed 's/.//3' b.txt
sf3
dgk

 

3、cut删除

[root@PC3 test]# cat b.txt
sfg3
dg2k
[root@PC3 test]# cut -b 3 --complement b.txt
sf3
dgk
[root@PC3 test]# cut -b 2-3 --complement b.txt
s3
dk

 

4、echo删除

[root@PC3 test]# cat b.txt
sfg3
dg2k
[root@PC3 test]# for i in `cat b.txt`; do echo "${i:0:2}${i:3}"; done
sf3
dgk

 

posted @ 2021-07-24 01:46  小鲨鱼2018  阅读(409)  评论(0编辑  收藏  举报