Using variables in printf format

前端 未结 4 1289
挽巷
挽巷 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条回答
  •  -上瘾入骨i
    2021-01-11 22:12

    does this count?

    idea is building the "dynamic" fmt, used for printf.

    kent$   awk '{n=7;fmt="%"n"-s%s\n"; printf fmt, $1, $2}' f 
    hello  this
    and    this
    

提交回复
热议问题