Answer the question
In order to leave comments, you need to log in
Who can help with awk file manipulation?
There are 10 columns with 10 rows. 1 word in each column.
using awk to swap the halves of the words along the diagonal a[i][i],
that is, the word WORD, we get RDWO. word length can be fixed. the result can be output or written to a file.
I can neither change halves of words, nor walk diagonally to change halves. can you advise something?
PS no need to write "google", tk. I read a lot of sites and manuals and did not find the information I needed
Answer the question
In order to leave comments, you need to log in
What's difficult?
#! /bin/awk -f
function reverse_halves(a)
{
n = length(a);
n2 = int(n / 2);
return substr(a, n2 + 1, n - n2) substr(a, 1, n2);
}
BEGIN { i = 1; }
{
for (j = 1; j <= NF; ++j)
printf("%s ", i == j ? reverse_halves($j) : $j);
printf("\n");
++i;
}
Throw an example of an input line and an example of an output line
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question