linux awk命令统计多个文件的总行数
1、测试数据
root@DESKTOP-1N42TVH:/home/test# ls test.txt test2.txt root@DESKTOP-1N42TVH:/home/test# cat test.txt a 3 d s 1 j z c m q e i 3 4 k h f 3 root@DESKTOP-1N42TVH:/home/test# cat test2.txt a 3 d s 1 j z c m q e i 3 4 k h f 3 root@DESKTOP-1N42TVH:/home/test# awk '{print NR}' test.txt test2.txt ## 生成两个文件总的索引 1 2 3 4 5 6 7 8 9 10 11 12 root@DESKTOP-1N42TVH:/home/test# awk 'END{print NR}' test.txt test2.txt ## 统计两个文件的总行数 12
root@DESKTOP-1N42TVH:/home/test# awk '{print FNR}' test.txt test2.txt
1
2
3
4
5
6
1
2
3
4
5
6
推荐这些文章:
1、测试数据
root@PC1:/home/test2# ls
test.txt
root@PC1:/home/test2# cat test.txt
a 3 5 d
s g e z
root@PC1:/home/test2# cat -A test.txt
a 3 5 d$
s g e z$
2、wc -c
root@PC1:/home/test2# ls
test.txt
root@PC1:/home/test2# cat test.txt
a 3 5 d
s g e z
root@PC1:/home/test2# cat -A test.txt
a 3 5 d$
s...
1、
root@PC1:/home/test# ls
test.txt
root@PC1:/home/test# cat test.txt
1
3
8
1
3
5
1
7
root@PC1:/home/test# sort test.txt | uniq -d ## 取出重复项
1
3
root@PC1:/home/test# sort test.txt | uniq -u ## 取出唯一项
5
7
8
...
1、测试数据
root@PC1:/home/test# ls
a.txt test.txt
root@PC1:/home/test# cat test.txt
3 s j
d z 4
x c 8
3 f z
c m d
root@PC1:/home/test# cat a.txt
1
2
3
2、
root@PC1:/home/test# cat a.txt
1
2
3
root@PC1:/home/test# cat test.txt
3 s j
d z 4
x c 8
3 f z
c m d
root@PC1:/home/test# sed '2r a.txt' t...
1、测试数据
root@DESKTOP-1N42TVH:/home/test2# ls
test.txt
root@DESKTOP-1N42TVH:/home/test2# cat test.txt
i j k
x c b
z c b
e g a
2、输出行序号
root@DESKTOP-1N42TVH:/home/test2# ls
test.txt
root@DESKTOP-1N42TVH:/home/test2# cat test.txt
i j k
x c b
z c b
e g a
root@DESKTOP-1N42TVH:/home/test2#...
tr用来转换或者删除一段文字。
1、实现大小写转换
root@DESKTOP-1N42TVH:/home/test# ls
a.txt
root@DESKTOP-1N42TVH:/home/test# cat a.txt ## 测试数据
i A E F
d q J M
S e N f
root@DESKTOP-1N42TVH:/home/test# cat a.txt | tr [A-Z] [a-z] ##全部转换为小写
i a e f
d q j m
s e n f
root@DESKTOP-1N42TVH:/home/test# cat a.txt
i A E F
d q J M
...
1、测试数据
root@PC1:/home/test2# ls
test.txt
root@PC1:/home/test2# cat test.txt ## 测试数据
a 3 5 d
s g e z
2、sed 实现
root@PC1:/home/test2# ls
test.txt
root@PC1:/home/test2# cat test.txt
a 3 5 d
s g e z
root@PC1:/home/test2# sed 's/ /\n/g' test.txt
a
3
5
d
s
g
e
z
3、cat + tr实现
root@PC1:...
1、测试数据
[root@centos7 test]# ls
test.txt
[root@centos7 test]# cat test.txt ## 测试数据
y j k
j k h
d j r
[root@centos7 test]# sed -n l test.txt
y\tj k$
\t\tj k\th$
\t\td\t\t j r$
2、
[root@centos7 test]# ls
t...
1、直接测试
root@DESKTOP-1N42TVH:/home/test# ls
test.txt
root@DESKTOP-1N42TVH:/home/test# cat test.txt ##测试数据
a 3 3 a 3 3
s 1 j s 1 j
z c m z c m
q e i q e i
3 4 k 3 4 k
h f 3 h f 3
root@DESKTOP-1N42TVH:/home/test# awk '{for(i = 4; i <= NF; i++) if($i == 3) {$i = "xxx"} {print $0}}' test.txt ## 将第...
1、
root@PC1:/home/test# ls
a.txt
root@PC1:/home/test# cat a.txt
1 D E
2 s d
3 d c
root@PC1:/home/test# awk '{print $NR}' a.txt ## 取矩阵对角线元素,正对角线
1
s
c
2、
root@PC1:/home/test# ls
a.txt
root@PC1:/home/test# cat a.txt
1 D E
2 s d
3 d c
root@PC1:/home/test# awk '{for(i = NF; i >= 1; i--) ...
1、测试数据
root@PC1:/home/test# ls
test.txt
root@PC1:/home/test# cat test.txt
3 4 2 9
1 3 5 4
3 7 8 4
2 3 4 6
2、对每一列数据进行求和
root@PC1:/home/test# ls
test.txt
root@PC1:/home/test# cat test.txt
3 4 2 9
1 3 5 4
3 7 8 4
2 3 4 6
root@PC1:/home/test# for i in `head -n 1 test.txt | awk '{print NF}' | ...
文章链接:https://www.dianjilingqu.com/3715.html
本文章来源于网络,版权归原作者所有,如果本站文章侵犯了您的权益,请联系我们删除,联系邮箱:saisai#email.cn,感谢支持理解。