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--) printf("%s ", $i); printf("\n")}' a.txt | awk '{print $NR}'  ## 取逆对角线元素
E
s
3
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 $(NF + 1 - NR)}' a.txt   ## 取逆对角线元素
E
s
3

 

相关文章:

  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2021-09-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-01-22
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案