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 new line affect print in awk?
Print the next column after a match in gawk
auto increment of a variable using awk
Split content into multiple file
awk sum addition math on fields & colums $ - strange results
How does the next command actually function
How to merge files based on common string (in different column number) using awk
Sorting a multidimensional array in awk
Awk splitting a string and comparison
How to search a pattern text and transpose in a single line till the next time same text is found?
Find average of numbers from a specific line
Search a file using combined keywords from two input files
awk to print of column headers if field has dot in it
gnuplot5 - sh: 1: Syntax error: “(” unexpected with awk
How to extend a string in awk
Dynamic row to column conversion in unix

Categories

HOME
batch-file
windows
turing-machines
jpa
pagination
gpu
pascal
fftw
devise
bookmarks
owin
java.util.logging
mxgraph
naivebayes
radgridview
cumulocity
keytool
alpacajs
standards
android-7.0-nougat
google-data-studio
xmonad
symbols
gulp-watch
inno-download-plugin
zxing
progress-bar
firebase-analytics
intersystems-cache
browser-sync
autodesk-designautomation
livelink
dst
jbutton
contacts
twos-complement
arduino-ide
numpy-broadcasting
parse-tree
sessionstorage
typesafe-config
visa
plaintext
attributeerror
datacachefactory
bindingnavigator
outputcache
http-request
signal-strength
photos
uiimage
servermanager
mesosphere
libgphoto2
lampp
pair-programming
azure-cli
appdomain
git-flow
seq
rackspace-cloud
d3-force-directed
mathcad
filenet
flex-monkey
xcode-server
drawstring
lean
angular-ui-typeahead
lz77
html-to-pdf
np-spring
jbase
dynatree
sciruby
include-guards
omnifaces
java-security
public-html
dbaccess
boost-program-options
genymotion-call
ss7
menubar
koala
android-usb
light
dtmf
ice-cube
inappsettingskit
flex++
fb.ui
robotlegs
pdfviewer
nokia-s40
fragmenttransaction
boost-msm
failing-tests
kqueue
catransform3d
automationelement
http-daemon
vs-android
build-environment
web-application-project
dsoframer
idatareader

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