Using bash to read elements on a diagonal on a matrix and redirecting it to another file

前端 未结 3 1871
无人及你
无人及你 2021-01-21 01:57

So, currently i have created a code to do this as shown below. This code works and does what it is supposed to do after I echo the variables:

a=`awk \'NR==2 {pri         


        
3条回答
  •  忘掉有多难
    2021-01-21 02:19

    An alternative using sed and coreutils, assuming space separated input is in infile:

    n=$(wc -l infile | cut -d' ' -f1)
    for i in $(seq 1 $n); do
      sed -n "${i} {p; q}" infile | cut -d' ' -f$i
    done
    

提交回复
热议问题