linux系統sed命令刪除前幾個字符、后幾個字符及特定字符前后字符


 

1、測試數據

[root@PC3 test]# cat a.txt 1234567849
1234567849
1234567849
1234567849

 

2、刪除前幾個字符

[root@PC3 test]# sed 's/..//' a.txt ## 刪除前兩個字符 34567849
34567849
34567849
34567849 [root@PC3 test]# sed 's/...//' a.txt ## 刪除前三個字符 4567849
4567849
4567849
4567849 [root@PC3 test]# sed 's/.\{3\}//' a.txt ## 刪除前三個字符 4567849
4567849
4567849
4567849 [root@PC3 test]# sed 's/.\{5\}//' a.txt ## 刪除前5個字符 67849
67849
67849
67849

 

3、刪除后幾個字符

[root@PC3 test]# sed 's/.$//' a.txt ## 刪除最后一個字符 123456784
123456784
123456784
123456784 [root@PC3 test]# sed 's/..$//' a.txt ## 刪除最后兩個字符 12345678
12345678
12345678
12345678

 

4、刪除特定字符及其前的字符

[root@PC3 test]# sed 's/.4//' a.txt 12567849
12567849
12567849
12567849 [root@PC3 test]# sed 's/..4//' a.txt 1567849
1567849
1567849
1567849

 

5、刪除特定字符及其后的字符

[root@PC3 test]# sed 's/4.//' a.txt 12367849
12367849
12367849
12367849 [root@PC3 test]# sed 's/4..//' a.txt 1237849
1237849
1237849
1237849

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM