Using awk to print characters of specific index on a line

前端 未结 3 1252
野的像风
野的像风 2020-12-05 09:25

Alright, so I know it is quite simple to print specific arguments of a line using $:

$ cat file
hello world

$ awk \'{print $1}\' file
hello
3条回答
  •  甜味超标
    2020-12-05 09:59

    Yes. You can use substr function :

    http://www.starlink.rl.ac.uk/docs/sc4.htx/node38.html

    In your case - for print chars from 2 through 8:

    echo "hello" | awk '{ print substr( $0, 2, 6 ) }'
    

    result is:

    ello

提交回复
热议问题