linux系統中如何刪除最后一列


 

1、測試數據

[root@centos7 test2]# cat a.txt e d g e s d g w a x d g n d i d [root@centos7 test2]# cat a.txt | sed -n l e d g e$ s d g w$ a x d g$ n d i d$

 

2、awk

[root@centos7 test2]# cat a.txt e d g e s d g w a x d g n d i d [root@centos7 test2]# awk '{$NF = ""; print $0}' a.txt e d g s d g a x d n d i [root@centos7 test2]# awk '{$NF = ""; print $0}' a.txt | sed -n l e d g $ s d g $ a x d $ n d i $ [root@centos7 test2]# awk '{$NF = ""; print $0}' a.txt | sed 's/.$//' | sed -n l e d g$ s d g$ a x d$ n d i$

 

 

3、awk  for循環

[root@centos7 test]# cat a.txt i e s m u w e i p q x z u n k e c b v y [root@centos7 test]# awk '{for(i = 1; i < NF; i++) printf("%s ", $i); printf("\n")}' a.txt i e s m w e i p x z u n e c b v [root@centos7 test]# awk '{for(i = 1; i < NF; i++) printf("%s ", $i); printf("\n")}' a.txt | sed -n l i e s m $ w e i p $ x z u n $ e c b v $ [root@centos7 test]# awk '{for(i = 1; i < NF; i++) printf("%s ", $i); printf("\n")}' a.txt | sed 's/.$//' | sed -n l i e s m$ w e i p$ x z u n$ e c b v$

 


免責聲明!

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



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