根据 URL 表格 12 列删除文本文件中的整行

根据 URL 表格 12 列删除文本文件中的整行

我有一个文件 abc.txt 该文件有 29 条记录 在这些记录中我们需要消除一些具有基于 URL 的 url 的行http://163.172.47.140:55555/

例如:

-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://163.172.47.140:55555/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323    

答案1

sed命令:

样本input.txt

-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://163.172.47.140:55555/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323
-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://192.172.45.130:55550/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323
-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://163.172.47.140:55555/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323

sed -i '/http:\/\/163\.172\.47\.140:55555\//d' input.txt
  • -i- 编辑文件到位
  • d- 删除符合特定模式的记录

最终input.txt内容:

-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://192.172.45.130:55550/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323

答案2

grep -vF 'http://163.172.47.140:55555/' input
  • -vF str- 所有不包含的行斯特

答案3

输入文件

-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://163.172.47.140:55555/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323
-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://195.175.45.130:55550/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323
-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://163.172.47.140:55555/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323

下面的命令删除包含“的行http://163.172.47.140:55555

命令:

 awk '!/http:\/\/163.172.47.140:55555/{print $0}' inputfile

输出

-       163.12372.473.1440  35010   2018-01-18 01:03:13 +0000       POST http://195.175.45.130:55550/?oip=163.172.47.140 HTTP/1.1   200     147  -est_useragent  -       -       test_refe    test_useragent  -       -       test_referer    text/json       323

相关内容