Linux-限制文本长度

Linux-限制文本长度,linux,Linux,我想根据列在不同文件中的名称提取一些列 我在以下链接中发现了这段有用的代码: 我试着编辑一些以打印页眉并限制页眉的长度 #!/bin/bash DATAFILE=${1:-data.txt} COLUMNFILE=${2:-list.txt} awk -v colsFile="$COLUMNFILE" ' BEGIN { j=1 while ((getline < colsFile) > 0) { col[j++] = $1 }

我想根据列在不同文件中的名称提取一些列

我在以下链接中发现了这段有用的代码:

我试着编辑一些以打印页眉并限制页眉的长度

#!/bin/bash

DATAFILE=${1:-data.txt}
COLUMNFILE=${2:-list.txt}

awk -v colsFile="$COLUMNFILE" '
   BEGIN {
     j=1
     while ((getline < colsFile) > 0) {
        col[j++] = $1
     }
     n=j-1;
     close(colsFile)
     for (i=1; i<=n; i++) s[col[i]]=i
   }
   NR==1 {
     for (f=1; f<=NF; f++)
       if ($f in s) c[s[$f]]=f
       printf ${$f:0:3}
   }
   { sep=""
     for (f=1; f<=n; f++) {
       printf("%c%s",sep,$c[f])
       sep=" "
     }
     print ""
   }
' "$DATAFILE"
我想要的输出是

ID,hea,hea
1,25.5,13.2
2,10.1,22.2
在我编辑代码以包含${$f:0:3}之后,它给出了一个语法错误。
请帮我做这个,谢谢

来自
man 1 awk

   substr(s, i [, n])      Return  the  at most n-character substring of s
                           starting at i.  If n is omitted, use  the  rest
                           of s.

   substr(s, i [, n])      Return  the  at most n-character substring of s
                           starting at i.  If n is omitted, use  the  rest
                           of s.
substr($f, 0, 3)