简体   繁体   中英

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}'

update according to OP's comment:

$ 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 /). EDIT: Adding variable's value into a variable as per OP's request.

A="/Modem/34"
VAR=${A##*/}
echo $VAR
34

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM