有的这样?
awk '{$5=$70;$6=$35;$7=$122;$8=$190;$9=$55;$10=$200;$11=$12;$12=$67}1' file
编辑:这会将某些列移动到位置 6 到 8,然后删除原始位置。
cat file
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
awk '{a[++i]=$0} END {for (i=1;i<=5;i++) printf "%s ",a[i];printf "%s %s %s ",a[16],a[8],a[22];a[16]=a[8]=a[22]="";for (i=6;i<=27;i++) printf "%s ",a[i]}' RS="[ \t]" file | awk '{$1=$1}1' OFS="\t"
A B C D E P H V F G I J K L M N O Q R S T U W X Y Z
EDIT2:更干净的版本
awk '
{
a[++i]=$0
}
END {
for (i=1;i<=5;i++)
printf "%s\t",a[i]
printf "%s\t%s\t%s\t",a[16],a[8],a[22]
a[16]=a[8]=a[22]=""
for (i=6;i<=27;i++)
if (a[i])
printf "%s\t",a[i]
}
' RS="[[:space:]]" file
EDIT3:如果您awk
不支持这种类型RS
,请使用此解决方案
awk '
{
for (i=1;i<=NF;i++)
a[i]=$i
}
END {
for (i=1;i<=5;i++)
printf "%s\t",a[i]
printf "%s\t%s\t%s\t",a[16],a[8],a[22]
a[16]=a[8]=a[22]=""
for (i=6;i<=27;i++)
if (a[i])
printf "%s\t",a[i]
}
' file