简体   繁体   English

如何找到特定格式的数字并筛选出一定范围的值?

[英]How to find numbers of specific format and filter out certain range of values?

如何找到格式0.xzy 0.xzy的数字,其中xzy是数字,x是8-9并在每次匹配(包括)之前将5行写到outputfile.txt

Find numbers in format 0.xzy ( xzy are numbers) 查找格式0.xzy xzy的数字( xzy是数字)

grep "^0.[0-9][0-9][0-9]$" file

Find cases where x is 8-9 查找x为8-9的情况

grep "^0.[89][0-9][0-9]$" file

To find numbers in the format 0.xzy (using word boundaries not forcing whole line match) and print the 5 line preceding the match -B5 and redirect the output to outfile : 要查找格式为0.xzy数字(使用单词边界而不强制整行匹配),并在匹配-B5之前打印5行,并将输出重定向到outfile

$ grep -B5 -Ew '0\.[0-9]{3}' file > outfile

# fix x to 8 or 9
$ grep -B5 -Ew '0\.[8-9][0-9]{2}' file > outfile

Note: the . 注意: . needs escaping to mean a literal period otherwise 01234 will match. 需要转义以表示原义句点,否则01234将匹配。 You will find man grep very helpful! 您会发现man grep非常有帮助!

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

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