You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用sed检测不含斜杠后缀的example.com字符串?

使用sed匹配example.com并排除example.com/的方法

核心需求

要筛选出数据库中所有包含example.com但未以/结尾的条目,比如错误的http://www.example.comfoo,同时排除正确的http://www.example.com/foo里的example.com/。

检测匹配命令

  • 匹配example.com后紧跟非/字符的情况:

    sed -n '/example.com[^\/]/p' your_database_file.sql
    

    [^\/]表示匹配example.com之后不是/的任意字符,精准定位像example.comfoo这类错误链接。

  • 同时覆盖example.com作为行尾的情况(比如单独出现的域名):

    sed -n '/example.com\($\|[^\/]\)/p' your_database_file.sql
    

    \($\|[^\/]\)表示要么example.com是行的结尾,要么后面跟的不是/,覆盖两种需要检测的场景。

修复错误链接的替换命令

如果要直接把错误的链接修正为正确格式(给example.com后补/),可以用:

sed 's/example.com\([^\/]\)/example.com\/\1/g' your_database_file.sql > corrected_database.sql

这个命令会将example.com后紧跟非/的部分,替换为example.com/加原字符,比如把example.comfoo转为example.com/foo。

内容的提问来源于stack exchange,提问作者Alain Lecompte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 12:25:18