number in string to find char in that string UNIX

前端 未结 2 2081
借酒劲吻你
借酒劲吻你 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
    
    0 讨论(0)
  • 2021-01-26 07:20

    No, you can't do that in sed, but it's easy enough in Awk.

    awk '{ print substr($2,$1,1) }' file
    
    0 讨论(0)
提交回复
热议问题