Results 1 to 10 of 11
hi guys!
im trying to use Unix and Lex to character match. basically i have a log file that contains the following:
[31/Jan/2006:23:45:57 962
[31/Jan/2006:23:45:57 893
[31/Jan/2006:23:45:57 827
[31/Jan/2006:23:45:57 2766
...
- 03-07-2007 #1
Unix Character matchin.
hi guys!

im trying to use Unix and Lex to character match. basically i have a log file that contains the following:
[31/Jan/2006:23:45:57 962
[31/Jan/2006:23:45:57 893
[31/Jan/2006:23:45:57 827
[31/Jan/2006:23:45:57 2766
[31/Jan/2006:23:45:57 2017
[31/Jan/2006:23:45:57 10991
i would like to use lex to achieve the answer:
31/Jan/2006 962
31/Jan/2006 893
31/Jan/2006 827
31/Jan/2006 2766
basically removing the time stamp from the date, but leaving all other characters
i have tried many ways, using lex, and awk - but cant seem to find an answer.
i would really appreciate anyone's help.
- 03-07-2007 #2
One option:
Code:[hector@centos1 ~]$ echo '[31/Jan/2006:23:45:57 962' | awk '{ sub(/\[/,"") ; sub (/:.*/,"",$1) ; print $0 }' 31/Jan/2006 962
- 03-07-2007 #3
Thanks for the reply

But strangely i get a syntax error:
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
Dont know whats going wrong.
- 03-07-2007 #4
Did you copy and paste that example exactly?
In your case you need to do:
If you're still getting errors post the exact errors. (Just take a copy of the whole session including the command you typed.)Code:$ awk '{ sub(/\[/,"") ; sub (/:.*/,"",$1) ; print $0 }' log-file-here
- 03-07-2007 #5
Originally Posted by anomie
i put the following code into a file names soln09awktime:
soln09log being the name of the log file im trying to manipulate.Code:$ awk '{ sub(/\[/,"") ; sub (/:.*/,"",$1) ; print $0 }' soln09log
then in the Unix to run the file im typing:
Code:$ soln09awktime
i get the same error:
Code:awk: syntax error near line 1 awk: illegal statement near line 1 awk: syntax error near line 1 awk: illegal statement near line 1
- 03-07-2007 #6
Could it be the word "sub"
what does this actually mean?
- 03-08-2007 #7
What distro are you seeing this error on? Also, what does awk --version | head -1 show you?
I thought all GNU/Linux used gawk (and awk is a symlink to it). This should work no problem. Try running it directly from the command line -- you don't need to make it into a script.
All this is doing is squeezing out the '[' character, and then squeezing out everything from ':' until the end of the word in the first column.
If you want to test whether the sub() function works on your awk implementation, just try:
Any complaints about the syntax? It should have printed Boo.Code:$ echo 'Moo' | awk '{ sub(/M/,"B"); print }'
- 03-08-2007 #8
im running it on a UNIX server over PuTTY.
i still get an error, so i assume sub doesnt work.
login1[u] echo 'Moo' | awk '{ sub(/M/,"B"); print }'
awk: syntax error near line 1
awk: illegal statement near line 1
- 03-08-2007 #9
is there a way of doing
using LEX, maybe this would avoid the error.Code:$ awk '{ sub(/\[/,"") ; sub (/:.*/,"",$1) ; print $0 }' log-file-here
- 03-08-2007 #10
You didn't state which version / awk you're using. If it's a SunOS box it could be nawk. Unfortunately different implementations of awk sometimes have different subtleties to their syntax.
I'm not interested in learning lex just to answer one question, so I will go away now.
Good luck.


Reply With Quote
