亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 如何通過指定時間,截取log指定行 [打印本頁]

作者: shintoky    時間: 2014-10-30 11:15
標(biāo)題: 如何通過指定時間,截取log指定行
如何通過指定時間,截取log指定行


求教各位大蝦,如何通過指定時間,截取log指定行,

2014/10/11 22222
2014/10/13 aaaaaaaaa
2014/10/14 33
2014/10/26 111111
2014/10/29 aaaaa
2014/10/29 dddddddddd
2014/10/29 ccccccc

比如 我需要10/26 - 10/29 的log
那么結(jié)果是
2014/10/26 111111
2014/10/29 aaaaa
2014/10/29 dddddddddd
2014/10/29 ccccccc
作者: jason680    時間: 2014-10-30 11:20
回復(fù) 1# shintoky

$ awk -vs="2014/10/26" -ve="2014/10/29" '$1>=s&&$1<=e' FILE
2014/10/26 111111
2014/10/29 aaaaa
2014/10/29 dddddddddd
2014/10/29 ccccccc
作者: 圣西羅門柱    時間: 2014-10-30 11:38

root@ubuntu:l# cat i
2014/10/11 22222
2014/10/13 aaaaaaaaa
2014/10/14 33
2014/10/26 111111
2014/10/29 aaaaa
2014/10/29 dddddddddd
2014/10/29 ccccccc
  1. root@ubuntu:# awk -F '[/ ]' '{T=$1$2$3;if(T>=20141026)print $0}' i
  2. 2014/10/26 111111
  3. 2014/10/29 aaaaa
  4. 2014/10/29 dddddddddd
  5. 2014/10/29 ccccccc
復(fù)制代碼

作者: shintoky    時間: 2014-10-30 11:42
回復(fù) 2# jason680


    謝謝 不過不知道為什么 打印出來的是空白 可能因為我時間戳 后面內(nèi)容比較多?
作者: shintoky    時間: 2014-10-30 11:45
回復(fù) 3# 圣西羅門柱

thanks but ..

root@1111:~ # awk -F '[/ ]' '{T=$1$2$3;if(T>=20141026)print $0}' file
awk: syntax error near line 1
awk: bailing out near line 1
作者: shintoky    時間: 2014-10-30 11:53
回復(fù) 1# shintoky

log實際內(nèi)容會更多

2014/10/26 19:47:27 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
2014/10/29 19:48:28 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
2014/10/29 19:49:29 ERROR V-16-2-13077 (server) Agent is unable to  Administrative intervention may be required.
作者: Shell_HAT    時間: 2014-10-30 13:00
回復(fù) 5# shintoky


    什么操作系統(tǒng)?
作者: tasteoftime_90    時間: 2014-10-30 14:38
[try@KeepTry patrol]$ cat keeptest
2014/10/26 19:47:27 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
2014/10/28 19:48:28 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
2014/10/29 19:48:28 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
2014/10/29 19:49:29 ERROR V-16-2-13077 (server) Agent is unable to  Administrative intervention may be required.
[try@KeepTry patrol]$ grep "10/2[6-8]" keeptest
2014/10/26 19:47:27 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
2014/10/28 19:48:28 ERROR V-16-2-13077 Agent is unable to  Administrative intervention may be required.
回復(fù) 1# shintoky


   
作者: shintoky    時間: 2014-10-30 15:14
回復(fù) 7# Shell_HAT


    Solaris 10
作者: shintoky    時間: 2014-10-30 15:16
回復(fù) 8# tasteoftime_90


    哈哈 這個可以 不過最好通過定義 字段1的時間來截取
grep 高手啊
作者: jcdiy0601    時間: 2014-10-30 15:17
  1. sed -n '/10\/2[6-9]/p' test
復(fù)制代碼
單純滿足你說的
作者: tasteoftime_90    時間: 2014-10-30 15:55
我也渣渣
不是很明白你什么意思
如果只是想自定義時間 那就改[]里的字段就行了
回復(fù) 10# shintoky


   
作者: Shell_HAT    時間: 2014-10-30 16:02
回復(fù) 9# shintoky
  1. /usr/xpg4/bin/awk -F '[/ ]' '{T=$1$2$3;if(T>=20141026)print $0}' file
復(fù)制代碼

作者: shintoky    時間: 2014-10-30 16:35
回復(fù) 11# jcdiy0601


      thanks a lot for reply
作者: shintoky    時間: 2014-10-30 16:38
回復(fù) 13# Shell_HAT


   謝謝 但是好像我這里不起作用 可能awk version 問題
作者: jason680    時間: 2014-10-30 17:45
本帖最后由 jason680 于 2014-10-30 17:47 編輯

回復(fù) 9# shintoky

try follow way in Unix like ...

1. write the day in the script directly
$ perl -lane 'if($F[0] ge "2014/10/26" && $F[0] le "2014/10/29"){print}' FILE
2014/10/26 111111
2014/10/29 aaaaa
2014/10/29 dddddddddd
2014/10/29 ccccccc

2. set the day in variable
$ export day_s="2014/10/26"; export day_e="2014/10/29"

$ perl -lane 'if($F[0] ge $ENV{"day_s"} && $F[0] le $ENV{"day_e"}){print}' FILE
2014/10/26 111111
2014/10/29 aaaaa
2014/10/29 dddddddddd
2014/10/29 ccccccc

   




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2