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