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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Grab 1

Status
Not open for further replies.

ranjit

Technical User
Apr 14, 2000
131
GB
Object: to print text between < > using substr

Input:
lo0:flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4>

Desired output:
UP,LOOPBACK,RUNNING,MULTICAST,IPv4


I have attempted the above, but have problems removing ">", using:
# nawk '{print substr($0, index($0,"<")+1)}' path_to_file
 
Code:
nawk -F'[<>]' '{print $2}' path_to_file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Something like this ?
awk '{sub(/.*</,"");sub(/>.*/,"");print}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or..
[tt]
awk 'match($0,"<[^>]*>"){print substr($0,RSTART,RLENGTH)}'[/tt]
 
Hi Ygor,
[tt]
Tried your bit of code:
nawk 'match($0,"<[^>]*>"){print substr($0,RSTART,RLENGTH)}' file

However the output is:
<UP,LOOPBACK,RUNNING,MULTICAST,IPv4>
[/tt]
 
[tt]awk 'match($0,"<[^>]*>"){print substr($0,RSTART+1,RLENGTH-2)}'[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top