Using variables in printf format

前端 未结 4 1342
挽巷
挽巷 2021-01-11 22:07

Suppose I have a file like this:

$ cat a
hello this is a sentence
and this is another one

And I want to print the first two columns with so

4条回答
  •  遥遥无期
    2021-01-11 22:40

    you can use eval (maybe not the most beautiful with all the escape characters, but it works)

    i=15
    eval "awk '{printf \"%$i-s%s\\n\", \$1, \$2}' a"
    

    output:

    hello          this
    and            this
    

提交回复
热议问题