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

How to increment a column value with an increasing number in a csv file
awk retain adjacent line based on duplicate field
Replace a specific column of a specific row with awk
split a large file, add first line as file name
awk script to calculate delay from trace file ns-3
Simplest way to find text by regex and replace by lookup table
Awk syntax error with system call
%a conversion specifier not recognized
AWK Curry Function - Can a function return a function?
printing mobile numbers with sed
Comparing rows in a text file
How to sort file contents by paragraph
How to use grep,awk or sed to extract text between two strings?
Renaming and editing a ChiP-seq bed file
Using grep-awk and sed in one-row-command result in a “No such file or directory” error
printing lines with duplicate words

Categories

HOME
service-worker
sonarqube
grok
ns-3
replace
xbee
tivoli
alsa
pearson-correlation
crystal-reports-2013
character
pattern-matching
pega
java.util.logging
3nf
esoteric-languages
dimensional-modeling
google-container-registry
nim
enterprise-miner
solrcloud
breadth-first-search
libigl
href
inno-download-plugin
easeljs
tosca
dapper-extensions
bringtofront
quantlib
comparable
record
kodi
github3.py
baidu-map
projects-and-solutions
css-position
opensmpp
news
apache-stanbol
numberpicker
android-softkeyboard
datacachefactory
logback-groovy
chronicle-map
placeholder
xmldocument
proget
vugen
insight
lightning
context-sensitive-grammar
seq
gpg-signature
flyout
javafx-css
pytables
custom-lists
seek
tooleap
jtwig
uiactionsheet
fuzzywuzzy
libav
blitline
vigenere
forwarding
batik
atoi
viola-jones
dronekit-android
avahi
canvg
entity-framework-4.3
at-job
browserify-shim
entry-point
paw
wcm
gae-quotas
clickbank
xmltodict
light
hidapi
observium
cnf
swfobject
apache-abdera
intersect
curb
window-decoration
pinch
jquery-tools
twitterizer
office-2007
dot-emacs
folding
zend-rest
pos-for-.net
echo3
flvplayback

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