LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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

Reply
 
Search this Thread
Old 03-21-2005, 05:31 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Rep: Reputation: 45
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
 
Old 03-21-2005, 05:40 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Here a non awk/sed sollution:

grep -o 7b24 <infile>

Using awk:

awk '/7b24/ { print $7 }' <infile>

Hope this helps.
 
Old 03-21-2005, 05:43 AM   #3
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
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
 
Old 03-21-2005, 05:48 AM   #4
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
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
 
Old 03-21-2005, 06:00 AM   #5
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 45
hi there,

in the example that you gave
Code:
grep 052c  filename | awk '{print $6}' > wherever
regards

slackie1000
 
Old 03-21-2005, 06:06 AM   #6
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
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.
 
Old 03-21-2005, 06:07 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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
 
Old 03-21-2005, 12:16 PM   #8
codeguy
LQ Newbie
 
Registered: Jan 2004
Distribution: Slackware
Posts: 28

Rep: Reputation: 1
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
 
Old 03-24-2005, 04:00 AM   #9
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
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
 
Old 03-24-2005, 04:16 AM   #10
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 45
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
 
Old 03-24-2005, 04:27 AM   #11
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
thx u save me
 
Old 03-24-2005, 05:33 AM   #12
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SED, AWK or PERL HELP embsupafly Programming 6 08-20-2005 09:07 PM
Sed & Awk hinetvenkat Linux - Software 4 05-30-2005 05:10 AM
sed or awk help requested tonyfreeman Programming 7 10-03-2004 12:23 AM
awk/sed help pantera Programming 1 05-13-2004 11:59 PM
sed/awk problem player_2 Programming 9 08-26-2003 06:09 PM


All times are GMT -5. The time now is 12:28 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration