awk


Extract multiple info from one line


I have the next log info from a Quake 3 server
187:38 ClientUserinfo: 1 \ip\192.168.10.22:27960\challenge\-642334061\qport\26940\protocol\68\name\^3exc3ls!or_^87\rate\8000\sex\male\handicap\100\color2\5\color1\4\snaps\20\authc\0\cl_guid\K3F07049EDE8AAF58CC3A979846237D7
390:06 ClientUserinfo: 14 \ip\192.168.10.21:27960\challenge\314934026\qport\62577\protocol\68\name\Moody_dog55\rate\16000\sex\male\handicap\100\color2\5\color1\4\snaps\20\authc\0\cl_guid\7FB6BDD1F08CCCC8CK3E9444930A35CD
I would like to extract the IP and name like this in a file
192.168.10.22 ^3exc3ls!or_^87
192.168.10.21 Moody_dog55
IP number and name can be in any variety.
How can this be done with sed, awk or grep?
awk approach:
awk -F'\' '{gsub(/:.*$/,"",$3); print $3, $11}' file
The output:
192.168.10.22 ^3exc3ls!or_^87
192.168.10.21 Moody_dog55
-F'\' - considering \ as field separator
gsub(/:.*$/,"",$3); - removing port number from IP address
perl approach:
perl -nle 'print $1," ",$2 if /\\ip\\([^\\]+):.*?\\name\\([^\\]+)/' file
You just remove the stuff you don't need, for example with sed:
sed 's/.*ip\\//;s/:.*\\name\\/ /;s/\\.*//' file
192.168.10.22 ^3exc3ls!or_^87
192.168.10.21 Moody_dog55

Related Links

awk equivalent for search of a pattern
Printing multiple lines with the same “largest” value using awk
Executing an action block in awk on multiple records in a file
Formatting a multiline record in awk
Awk print $0 print all lines of my files to the last position of column ;how I can print at first?
using awk to find pattern if line starts with “>” and add at the end of it the number of occurences of the pattern
awk to count and print header row of file
awk remove two row based on one row
How can I make nawk evauluate two if conditions as one?
sum up the output of 'pkpgcounter -ccmyk' in groups Cyan, Magenta, Yellow, Black to calculate ink usage
Using a loop variable to print fields in awk [duplicate]
print rest of line after n consecutive character appears
Sed / Awk : replace the first occurrence of a pattern with the content of another file
What could be regex for below logs?
AWK command for parameterize
Run command inside awk and store result inplace

Categories

HOME
django
c++11
ggplot2
graphics
requirements
gradient
appcelerator
ms-access-2016
javacc
database-normalization
jax-ws
openpyxl
mautic
libc
pybossa
libusb
alpacajs
smartclient
sse
poedit
easeljs
exploit
strongname
draft-js-plugins
xcode-ui-testing
licensing
handler
hard-drive
numpy-broadcasting
swagger-php
openalpr
typesafe-config
jvmti
chef-solo
tasm
trigonometry
android-checkbox
oim
snapchat
double-click
term
netbeans6.8
facebook-pixel
launchctl
identification
posixct
context-sensitive-grammar
spring-data-couchbase
opengl-4
payload
d3-force-directed
testrail
reachability
taocp
cudd
omxplayer
flex4.6
resourcemanager
model-associations
i386
jclouds
pre-build-event
mediametadataretriever
bizagi
uiactionsheet
httpruntime.cache
concept-insights
sapi
avisynth
computer-architecture
android-launcher
toolkit
ansi
ms-access-2000
user-permissions
phpldapadmin
mobility
winginx
spring-remoting
getopt
c++builder-xe5
model-driven-development
css-reset
fb.ui
wimax
fusefabric
kqueue
filemerge
android-holo-everywhere
uipagecontrol
msr
ruby-1.8
aspmenu
eclipse-marketplace
opml
duplex
lalr
feasibility
google-wave
asynchronous-wcf-call
todos
java1.4
xslcompiledtransform
online-storage

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App