用grep文件中字符串变量 [英] grep variable string in file

查看:1263
本文介绍了用grep文件中字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在文件中找到字符串:

I must find in a file this string:

200 https://www.example.example

价值200 randomic,我一定要找到每一个HTTP返回code(200前,301,404等...等)

The value 200 is randomic, I must find every HTTP return code (ex 200, 301, 404 etc...etc)

我怎么可以grep仅此字符串返回code变量中(我不想指定grep命令每返回code)?

How can I grep only this string with return code variable (I don't want specify every return code in grep command)?

cat file.txt | grep "*** http*" 

不过,这是行不通的。

But it doesn't work.

推荐答案

所以你要匹配开头的三位数任何线路,其次是HTTP?

So you want to match any line starting with a three digit number, followed by "http"?

grep -E '^[0-9]{3} http' file.txt

更精确由fedorqui(感谢)的建议是这样的:

More accurate as suggested by fedorqui (thanks) would be this:

grep -E '^[1-5][0-9]{2} http' file.txt

这在范围100-599,这是接近HTTP状态codeS的范围相匹配的号码。

This matches numbers in the range 100-599, which is closer to the range of HTTP status codes.

这篇关于用grep文件中字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆