Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print information between [ and ] 1

Status
Not open for further replies.

sunixadm

Technical User
Sep 20, 2001
73
DE
Hello masters of AWK,

I've been trying for hours to solve this problem and need some help please.

I have files with content similar to
---cut---
5 1 0x406B01AC[free(0x406b0120)+0x8c] 0x405192BC[aaa_idb_name_cleanup(0x4051929c)+0x20] 0x4051F840[free_general_db(0x4051f828)+0x18] 0x4051F8F4[cleanup_general_db(0x4051f8d4)+0x20]
0x4050FD54 0x40515FF0 0x40501458 0x4051B5A80x4050FD54[aaa_db_cleanup_db_element(0x4050fc28)+0x12c] 0x40515FF0[aaa_acct_post_event(0x40515258)+0xd98] 0x40501458[aaa_event_send_and_free(0x405012fc)+0x15c] 0x4051B5A8[aaa_uid_send_event(0x4051b534)+0x74]
0 7 0x41AE8AD4[bc32_odd_loop(0x41ae8ac8)+0xc] 0x406B70D0[log_debug_buffer(0x406b706c)+0x64] 0x406B7240[validblock_diagnose(0x406b7114)+0x12c] 0x406B58E4[validblock(0x406b5404)+0x4e0]
0x406B0250 0x405192BC 0x4051F840 0x4051F8F4 0x406B0250[free(0x406b0120)+0x130] 0x405192BC[aaa_idb_name_cleanup(0x4051929c)+0x20] 0x4051F840[free_general_db(0x4051f828)+0x18] 0x4051F8F4[cleanup_general_db(0x4051f8d4)+0x20]
%
---cut---
and need to print the contents between [ and ] but nothing else.

Thanks in advance for your help.
-Joe
 
A starting point:
awk '!/\[/{next}{split($0,a,"[");for(i in a)if(a~/]/){split(a,b,"]");print b[1]}}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,

That hit the nail on the head!
Cheers,
-Joe
 
Given the sample pattern given:
Code:
awk -F'[][]' '{print $(NF-1)}' myFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top