Grep problem

Hi Guys

i have a file with hundreds of lines like this

alerts.log2011-29:08/29/2011 12:47:56 XYZ_1234 ABSCTT  One Failed File Push To Remote Server Failed  ABC.DEF.1234
alerts.log2011-29:08/29/2011 12:47:56 XYZ_1234 ABSCTT  One Failed File Push To Remote Server Failed  WXYZ_ABC001

i want to take date and last column of file (till first special character) at a time.

expected output of command is:

08/29/2011 12:47:56  ABC
08/29/2011 12:47:56  WXYZ

Here i m facing 2 problems
1) when i cat this file and grep any one of these 2 i cant grep other in same command :confused:
2) In last column i want to pull the information only till first special character found which is not consistent in the file, its flooded with all kind of them. :wall:

Any help is greatly appreciated folks

Regards

If your grep supports -o you can do:

grep -o '[0-9][0-9]/[0-9][0-9]/[0-9]*[^_]*' infile

yes grep -o is supported,

but catch here is, the last column can have any special character not only [^_] , it can have dot, hyphen, underscore or hash, how to catch all of them?

How about using sed and match anything not A-Z or a-z:

d2='[0-9][0-9]'
sed -n "s#.*\($d2/$d2/$d2$d2 $d2:$d2:$d2\) "'.* \([a-zA-Z]*\)[^A-Za-z][^ ]*$#\1 \2#p' infile