字符串中的数字以在该字符串中查找字符 UNIX [英] number in string to find char in that string UNIX
本文介绍了字符串中的数字以在该字符串中查找字符 UNIX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含单词和数字的字符串,如下所示:
I have a string that contains a word and a number, like this:
"6 ovenbread"
如何读取数字(我们称之为 i
)并找到单词的第 i
个字符?
How can I read the number (let's call it i
) and find the i
th character of the word?
似乎 s/([0-9]) (.){\1}/\2/
不起作用.
推荐答案
我觉得 awk 更简单,它有 substr
功能,可以让你选择第 n 个字母.
I think awk is easier, it has substr
function, allows you to pick the n-th letter.
awk '{print substr($2,$1,1)}'
使用您的数据:
kent$ echo "6 ovenbread"|awk '{print substr($2,$1,1)}'
r
这篇关于字符串中的数字以在该字符串中查找字符 UNIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文