求教awk按格式取时间段内内容

JohnLiu 2011-05-27 10:20:29
文件内的格式 大概是这样的
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-21 17:27:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=

1: 我想以 $$ 作为分割符 但是用 awk -F $$ 无效
2: 在 $$ts=xxxx-xx-xx xx:xx:xx 这个纪录时间的值内我想 用awk 抓出我指定的一段 时间之内的内容

求教! 有哪位好心人 帮忙看看 用SHELL或C实现 不限
...全文
226 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
JohnLiu 2011-05-28
  • 打赏
  • 举报
回复
已经解决了 谢谢楼上各位...
JohnLiu 2011-05-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jerry409 的回复:]

C/C++ code

echo -n `awk '{ print $5; print $6 }' test.txt` | sed 's/$$ts=//'



试试这个,最后的显示结果是

2011-04-21 17:27:11
[/Quote]

谢谢 但我要的是 取出相对应的时间段的内容

比如我想取出 2011-05-27 11:15:00 到 2011-05-27 11:30:00 的内容
意思就是$$ts=xxxx-xx-xx xx:xx:xx 符合我指定的时间段
jerry409 2011-05-27
  • 打赏
  • 举报
回复

echo -n `awk '{ print $5; print $6 }' test.txt` | sed 's/$$ts=//'


试试这个,最后的显示结果是

2011-04-21 17:27:11
jerry409 2011-05-27
  • 打赏
  • 举报
回复
原来是这个意思啊。
那就用这个吧

awk 'BEGIN {FS="$"} {if ($11 >= "ts=2011-04-21 10:00:00 " && $11 <= "ts=2011-04-25 10:00:00 ") {print $0}}' test.txt


test.txt内容是:

$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-21 17:27:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-22 16:27:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-23 12:26:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-24 17:27:12 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-25 11:27:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=


输出结果是:


[root@Han test]# awk 'BEGIN {FS="$"} {if ($11 >= "ts=2011-04-21 10:00:00 " && $11 <= "ts=2011-04-25 10:00:00 ") {print $0}}' test.txt
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-21 17:27:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-22 16:27:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-23 12:26:11 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=
$$callid=1303377714104-9470 $$thread=[http-99-Processor23] $$host=20.1.83.67 $$userid=root $$ts=2011-04-24 17:27:12 $$remotecall=[accountmanage] $$debuglevel=ERROR $$msg=

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧