简体   繁体   English

grep 或 awk:匹配 alpha 前缀数字范围

[英]grep or awk : Match on alpha prefixed number range

How would one match on a range of system names that are prefixed by letters?如何匹配一系列以字母为前缀的系统名称?

Given: sfc30700 through sfc30900给定:sfc30700 到 sfc30900

Want all systems listed in file from sfc30750 to sfc30850 for example, and the sequence not fully populated.例如,希望文件中列出的从 sfc30750 到 sfc30850 的所有系统,并且序列未完全填充。

I did attempt to use egrep like so, however it returns an error.我确实尝试过像这样使用 egrep ,但是它返回一个错误。

cat mahinelist.txt | egrep ':[[:sfc:]]\{30750,30850\}:'
egrep: Invalid character class name

This prints out all lines containing " sfc " directly followed by a number between " 30750 " and " 30850 ".这将打印出所有包含“ sfc ”的行,后跟“30750”和“ 30850 ”之间的数字

$ cat file
sfcdd30784
sfc30689
word sfc30750 word
sfc30753
sfc30756
sfc30900
sfc30901
daw30900

$ awk '{ n=match($0,"sfc"); m=substr($0,n+3,5)*1;
    if(m>=30750 && m<=30850){ print } }' file
word sfc30750 word
sfc30753
sfc30756

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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