Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
03-21-2005, 05:31 AM
#1
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Rep:
awk and sed issues
Hi i need to select from the following text only the bold number
13:28:53.349803 IP 10.1.0.1.innosys-acl > 10.1.4.3.search-agent: UDP, length: 1316
0x0000: 4530 0540 a353 0000 7f11 7b24 0a01 0001 E0.@.S....{$....
0x0010: 0a01 0403 0585 04d2 052c 5d11 4700 4410 .........,].G.D.
0x0020: 5f1c 05fc c837 1121 3a7d 2af1 653e d8eb _....7.!:}*.e>..
0x0030: 211a b978 a6ee 355a 6ef4 caca 1359 0744 !..x..5Zn....Y.D
0x0040: 4082 6060 6363 d818 2a9a b9b6 e212 1ed4 @.``cc..*.......
0x0050: e4ae
I have tried to do it with awk
cat dumpme | awk ' {print $7}' |
but this returns the whole columng
length:
7b24
5d11
2af1
caca
b9b6
How i can truncate the unecessary rows? Thank u in advance
03-21-2005, 05:40 AM
#2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Hi,
Here a non awk/sed sollution:
grep -o 7b24 <infile>
Using awk:
awk '/7b24/ { print $7 }' <infile>
Hope this helps.
03-21-2005, 05:43 AM
#3
Member
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293
Rep:
Or if you dont know what the number will be and just want that field,
Code:
cat dumpme | awk ' {print $7}' | tr "\n" " " | cut -d " " -f 3
03-21-2005, 05:48 AM
#4
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Original Poster
Rep:
thx
thx a lot ahh your solution is great,,, but still i have one little problem to face.. My file has many times the following table (...as you can see below)
13:44:05.780466 IP 10.1.0.1.cadkey-tablet > 10.1.4.3.search-agent: UDP, length: 1316
0x0000: 4530 0540 6920 0000 7f11 b557 0a01 0001 E0.@i......W....
0x0010: 0a01 0403 0578 04d2 052c a7f1 4700 4414 .....x...,..G.D.
0x0020: 06c0 0d11 bb24 9df0 8a79 562a ffb2 a81f .....$...yV*....
0x0030: aaf8 1703 88c0 f7fb 133c 7bd9 fa3c 553c .........<{..<U<
0x0040: 3ff4 54ad 50fa 2a1f 403d 2281 e028 8b87 ?.T.P.*.@="..(..
0x0050: b018 ..
13:44:05.780711 IP 10.1.0.1.cadkey-tablet > 10.1.4.3.search-agent: UDP, length: 1316
0x0000: 4530 0540 6921 0000 7f11 b556 0a01 0001 E0.@i!.....V....
0x0010: 0a01 0403 0578 04d2 052c 0180 4700 443b .....x...,..G.D;
0x0020: 6700 ffff ffff ffff ffff ffff ffff ffff g...............
0x0030: ffff ffff ffff ffff ffff ffff ffff ffff ................
0x0040: ffff ffff ffff ffff ffff ffff ffff ffff ................
0x0050: ffff ..
13:44:05.780950 IP 10.1.0.1.cadkey-tablet > 10.1.4.3.search-agent: UDP, length: 1316
0x0000: 4530 0540 6922 0000 7f11 b555 0a01 0001 E0.@i".....U....
0x0010: 0a01 0403 0578 04d2 052c 6c84 4700 4412 .....x...,l.G.D.
0x0020: 9008 503b b00d 493b 955f b741 f27f fb47 ..P;..I;._.A...G
0x0030: 97ab c856 19a0 3a08 7606 0f60 97cd a8ff ...V..:.v..`....
0x0040: e62d fa38 26f4 d51d dde8 29d4 a156 a7f8 .-.8&.....)..V..
0x0050: 9802 ..
Which means that now i need every bold number
03-21-2005, 06:00 AM
#5
Senior Member
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037
Rep:
hi there,
in the example that you gave
Code:
grep 052c filename | awk '{print $6}' > wherever
regards
slackie1000
03-21-2005, 06:06 AM
#6
Member
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293
Rep:
You can selsect more than one line with awk, and more than one field with the cut command, eg.
Code:
cat dumpme | awk ' {print $7,9,12}' | tr "\n" " " | cut -d " " -f 3,7,11
Just an example, use correct line and field numbers to suit your purpose.
Last edited by ahh; 03-21-2005 at 06:13 AM .
03-21-2005, 06:07 AM
#7
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Hi,
It seems that the string is not always on position 7 (it's 6 in the second example).
If your grep supports it you can use the grep -o example I gave in my previous answer. I.e:
grep -o 052c <infile>
You will end up with this (input file is your second example):
grep -o 052c infile
052c
052c
052c
03-21-2005, 12:16 PM
#8
Member
Registered: Jan 2004
Distribution: Slackware
Posts: 187
Rep:
Assuming you dont always want to search for the exact number, (052c) but the exact same line and column you can do this:
Code:
awk '/0x0010:/ {print $6}' < x.txt
That will print column 6 for every line with '0x0010:' in it.
-Andy
03-24-2005, 04:00 AM
#9
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Original Poster
Rep:
thx a lot... u really helped me...
and something else plz
if i want to remove the spaces between these 3 columns/?
34 36 13
23 43 23
42 56 93
03-24-2005, 04:16 AM
#10
Senior Member
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037
Rep:
hi there,
if this 3 columns is your complete file, you can use sed:
Code:
sed "s/ //g" filename
you can also use a text editor to change that.
regards
slackie1000
03-24-2005, 04:27 AM
#11
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Original Poster
Rep:
thx u save me
03-24-2005, 05:33 AM
#12
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Original Poster
Rep:
thx but i need now something more tricky.... look plz at the bold letters and help me
13:44:05.780466 IP 10.1.0.1.cadkey-tablet > 10.1.4.3.search-agent: UDP, length: 1316
0x0000: 4530 0540 6920 04d2 052c a7f1 4700 4414 .....x...,..G.D.
0x0020: 06c0 0d11 bb24 9df0 8a79 562a ffb2 a81f .....$...yV*....
0x0030: aaf8 1703 88c0 f7fb 133c 7bd9 fa3c 553c .........<{..<U<
0x0040: 3ff4 54ad 50fa 2a1f 403d 2281 e028 8b87 ?.T.P.*.@="..(..
0x0050: b018 ..
How i can select them?
Last edited by alaios; 03-24-2005 at 05:50 AM .
All times are GMT -5. The time now is 06:26 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News