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$
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。