Doing this in pure shell is a poor approach IMHO. My suggestion would be to use something such as Perl, Python or Ruby to parse the input. In Ruby you might use something like:
#!/usr/bin/env ruby
require 'cgi'
line = "2009-12-16 00:00:43,970 INFO [btpool0-12194://webmail.amit.com/Microsoft-Server-ActiveSync?Cmd=Ping&User=rahul%40kke.amit.com&DeviceId=androidc986729649&DeviceType=Android] [] sync - POST Microsoft-Server-ActiveSync?Cmd=Ping&User=ritesh%40kke.amit.com&DeviceId=androidc986729649&DeviceType=Android"
if line =~ /User=([^&]+)/
user = CGI.unescape($1)
puts "Found User: #{user}"
end
if line =~ /DeviceId=([^&]+)/
id = CGI.unescape($1)
puts "Found Device ID: #{id}"
end # Output:
Found User: rahul@kke.amit.com
Found Device ID: androidc986729649 L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124