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

String Grab

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
 
it may not be pretty but what's wrong with
Code:
echo $string | cut -f 2 -d '<' | cut -f 1 -d '>'

Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
 
Either of these will work:

#!/usr/dt/bin/dtksh

for b in $(echo "lo0:flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4>")
do
print ${b:18:34}
done

*****************************************************************
#!/bin/ksh

for t in $(echo "lo0:flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4>")
do
x=${t##*\<}
p=${x%%\>*}
print $p
done
 
Another option:

Code:
string="lo0:flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4>"
echo $string | sed 's/.*<\(.*\)\>.*/\1/'

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top