You are not logged in.
I wrote a script that generates a 12 columns in a text file based on parsing my apache logs. I need to remove any line that match the following two conditions:
1) <TAB>200<TAB>
2) <TAB>206<TAB>
Where <TAB> is a literal tab as my other stuff reads tab deliminated files. The following grep works to match simply '200' or '206' but I can't get the grep syntax correct to match with the trailing and leading tabs.
grep -w '200\|206' parsed.log
Any help is appreciated.
EDIT: Finally!
grep -E $'\t200\t\|\t206\t' parsed.log
EDIT2: Rrrr... the above works under zsh but not under bash... what's my problem?
Last edited by graysky (2013-07-13 16:16:08)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Does this work:
grep -E '(\t200\t)|(\t206\t)' parsed.log
Edit: Wait, that matches a literal 't', doesn't it?
I think you need this:
grep -P '[\t]200[\t]|[\t]206[\t]' parsed.log
Last edited by thisoldman (2013-07-13 15:33:54)
Offline
It fails under bash because bash treats "\|" as a literal "\|", i.e. a backslash and then a pipe. zsh will turn it into just "|". Anyway you don't have to escape the |, so "grep -E $'\t200\t|\t206\t' parsed.log" should work.
Offline
Thanks for the assistance. Will mark as solved.
...actually, my original thought was flawed. I actually need to preform this grep query within column #9 in the text file. Simply doing it on a line-by-line basis does not catch the errors. I need to some how mate this up with awk.
EDIT: Here is a sample of the file: http://repo-ck.com/PKG_source/test.txt
Last edited by graysky (2013-07-13 15:58:23)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
graysky, do both conditions have to be met at the same time? Is it 1) AND 2) or 1) OR 2)?
Offline
graysky, do both conditions have to be met at the same time? Is it 1) AND 2) or 1) OR 2)?
Is it an or: either 200 or 206 (it will never be both). I edited post #4 with a sample file.
Last edited by graysky (2013-07-13 15:48:25)
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Thanks for the assistance. Will mark as solved.
...actually, my original thought was flawed. I actually need to preform this grep query within column #9 in the text file. Simply doing it on a line-by-line basis does not catch the errors. I need to some how mate this up with awk.
EDIT: Here is a sample of the file: http://repo-ck.com/PKG_source/test.txt
Try
awk '$9 ~ /20[0,6]/' test.txt
The sample has only 200 in the 9th column, but I edited it and it worked with 206 too.
Offline
Oooops.
You're using tab-deliminated files, so try
awk -F '\t' '$9 ~ /20[0,6]/' test.txt
instead.
Sorry for bumping.
Offline
@karol - Thank you. That solved it.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline