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: substitute function sub() didn't work
Awk error message targeting a parentheses
awk to compare file line by line
awk capability cut capability
restrict pattern to specified strings
awk help needed
How can I find “.dat” within all *.mk files?
awk: search string in diffrent file then append the result in the output
awk to read specific column from a file
replace current record on awk add space
Compute transitive closure
how does awk differentiate string from number
awk multiple variables for multiple file processing
how to print certain column with numbers only in awk
Merging two rows in AWK
awk: how to execute a command and read its output

Categories

HOME
embedded
ng-idle
nvd3.js
phpmyadmin
sh
mips
crystal-lang
discrete-mathematics
accessibility
spin
owin
jxl
xcodebuild
automatic-ref-counting
coin3d
entitymanager
searchview
soci
pyramid
asp.net-core-webapi
question2answer
inno-download-plugin
object-storage
aggregation
resourcebundle
mount
bulletphysics
corpus
delimiter
bringtofront
paperjs
bioinformatics
vex
realm-mobile-platform
google-earth
corenlp-server
boost-asio
anki
getpixel
openproject
z-notation
node-mssql
linq-to-objects
unordered-map
setup.py
getchar
mongotemplate
semantic-logging
backbone-collections
stax
watch-os-2
macaulay2
nikeplus-api
xdoclet
lua-telegram-bot
aspen
realsense
cycle2
qbxml
assertion
forwarding
airbrake
nsurlsessiondatatask
bufferedinputstream
java-security
cryptographichashfunction
viewer
contrast
rmysql
alternate
conditionaltagsupport
xmltodict
visual-studio-express
gd-graph
windows-phone-8-sdk
gpars
workitem
swfobject
veracity
paginator
catransform3d
u2netdk
google-ajax-api
entitydatasource
nhprof
vs-android
dot-emacs
tabpanel
cfwindow
todos
int64

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