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!

Extracting text

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH

Hi

I have a file ( Name errorfile.txt) full of lines like the one below

$APP_SCR/dwh_exit_error.scr "$?" "Error in <dwh_hub_if_ow_build_if0005.sql> Exiting"

I need to extract the filename within < >

I tried doing a
awk '{ sub(/^[^>]*>/,""); sub(/<.*$/,""); print $0 } ' errorfile.txt

but it comes back with syntax errors and I cant figure out why.

Any ideas pls ?
 
Something like this ?
sed -e 's!^.*<!!;s!>.*!!' errorfile.txt

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Try..

awk '{ sub("^[^<]*<",""); sub(">[^>]*$",""); print $0 } ' errorfile.txt

Or..

awk 'match($0,"<.*>") {print substr($0,RSTART+1,RLENGTH-2)}' errorfile.txt
 
Make the "<" and the ">" field separators:a
Code:
[b]
awk -F'<|>' 'NF==3{print $2}'
[/b]
 
The same with alternate field separator specification :
Code:
awk -F'[<>]' 'NF==3{print $2}'[code]


Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top