[英]How grep two digit numeric value from grep command
我有像/ Modem / 34这样的字符串行,现在我只想提取34 ..如何做到这一点。
尝试
grep -Eo '[0-9][0-9]' infile
If you want to extract the text after last slash: 如果要在最后一个斜杠后提取文本:
grep -o '[^/]*$'
or 要么
awk -F'/' '{print $NF}'
$ sed 's#.*/##;s/ .*//'<<< "a/b/c/this fo ba"
this
try: 尝试:
A="/Modem/34"
echo ${A##*/}
Saving string into a variable named A and then using shell's parameter expansion to get only the 34(because it will remove everything till /). 将字符串保存到名为A的变量中,然后使用shell的参数扩展仅获取34(因为它将删除所有内容直到/)。 EDIT: Adding variable's value into a variable as per OP's request.
编辑:根据OP的请求将变量的值添加到变量中。
A="/Modem/34"
VAR=${A##*/}
echo $VAR
34
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.