我有一个标题,如下所示:
Unix Linux Trumpet Perl 1|1 1|2 1|3
我怎样才能将标题更改为这样的内容:
1 1 1
Unix Linux Trumpet Perl 1 2 3
我尝试使用 for 循环:
awk 'for (i=0; 1<row.length; i++)
if values[i] == "|"
然后拆分该行并将其附加到同一列中,但它不起作用。我怎样才能在 Linux 上做到这一点?
答案1
单程:
$ cat file
Unix Linux Trumpet Perl 1|1 1|2 1|3
$
$ awk -F"[ |]" '{
printf "%-10s %-10s %-10s %-10s %-3s %-3s %-3s\n","","","","",$5,$7,$9;
printf "%-10s %-10s %-10s %-10s %-3s %-3s %-3s\n",$1,$2,$3,$4,$6,$8,$10;
}' file
1 1 1
Unix Linux Trumpet Perl 1 2 3