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$

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-02-08
  • 1970-01-01
  • 2021-12-21
猜你喜欢
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案