liujiaxin2018

1、测试数据

[root@centos79 test]# cat a.txt
e r w i
s g n c
w d h x

 

2、awk

[root@centos79 test]# cat a.txt
e r w i
s g n c
w d h x
[root@centos79 test]# awk \'{print NF}\' a.txt
4
4
4
[root@centos79 test]# awk \'END{print NF}\' a.txt
4

 

3、grep + wc -l

[root@centos79 test]# cat a.txt
e r w i
s g n c
w d h x
[root@centos79 test]# head -n 1 a.txt | grep -o " " | sed "1i xx" | wc -l
4

 

4、tr + wc -l

[root@centos79 test]# cat a.txt
e r w i
s g n c
w d h x
[root@centos79 test]# head -n 1 a.txt | tr " " "\n" | wc -l
4

 

分类:

技术点:

相关文章:

  • 2021-12-21
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2021-07-29
  • 2021-11-23
  • 2021-07-20
  • 2021-12-19
  • 2021-05-12
相关资源
相似解决方案