sorting - 如何 Grep 特定的 URL 目录级别?
问题描述
例如,我有一个列表:
https://google.com/one/
https://google.com/one/two/
https://google.com/oneone/
https://google.com/one/two/three/
如何grep只是一级目录?所以,我的清单会是这样的:
https://google.com/one/
https://google.com/oneone/
或者只是像这样的二级端点:
https://google.com/one/two/
谢谢!
解决方案
awk 将是一个更好的工具
awk -F\/ 'NF==5 && $4 ~ /one/ { print $1"/"$2"/"$3"/"$4 }' file
https://google.com/one/
https://google.com/oneone/
awk -F\/ 'NF==6 && $4 ~ /one/ { print $1"/"$2"/"$3"/"$4 }' file
https://google.com/one/two/
使用 / 作为字段分隔符并检查字段数,并且该字段 4 包含一个,打印结果。
推荐阅读
- .net - 使用 codefirst 连接并创建数据库,错误 26
- rest - OWASP 保护 restapi 免受点击劫持的安全指南,它们准确吗?
- javascript - 如何解决 JavaScript 中的堆栈问题?
- kotlin - 智能投不投String?!value.isNullOrBlank() 之后的字符串
- android - 为什么我在 StringReader read() 中得到 IndexOutOfBoundsException?
- http - 与本地主机上的内部反向代理的内部 ServiceFabric 通信
- virtocommerce - 来自 Github 的 virto 商务部署
- html - CSS:强制无线电输入检查
- javascript - 在 Angular JS 中过滤我的 JavaScript 中的未定义
- android - 如何在 Delphi Android 应用程序中调用本机相机?