number in string to find char in that string UNIX

前端 未结 2 2106
借酒劲吻你
借酒劲吻你 2021-01-26 06:57

I have a string that contains a word and a number, like this:

\"6 ovenbread\"

How can I read the number (let\'s call it i) and fin

2条回答
  •  死守一世寂寞
    2021-01-26 07:13

    I think awk is easier, it has substr function, allows you to pick the n-th letter.

    awk '{print substr($2,$1,1)}'
    

    with your data:

    kent$ echo "6 ovenbread"|awk '{print substr($2,$1,1)}'
    r
    

提交回复
热议问题