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

extract string between two delimiters.

Status
Not open for further replies.

izq

IS-IT--Management
Jan 8, 2008
3
ES
for a text file, i want to extract the strings between two delimiters.

for example, init delimiter <, end delimiter >

I need to find and print each string (normaly more than one per line) between this delimiters in each line of the file.

I suppose this must be simple, but I suppose that I'm silly too.

Thanks for help,
izq.
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I Tray with FS and RS trying to separete in fields o records based on the delimiter.

also I reed the faq about awk and the way must use match or gensub for this kind of work.

for example, suposse ini delimiter X and end delimiter F

echo foo foo foo XabF foo foo foo foo XbcF foo foo | gawk '{ print gensub(/X([^X]+)F/, "\\1", "g")}'

and any conbination of .+ .* possible. the result never is:

ab
bc

that is the one I'm looking for.

All I try is in command line, is the way I'm looking for.

As you can see, I'm new on awk.
I suppose this kind of script must be simple, but I don't find nothing that feet with my need.

thx,
izq
 
A starting point:
awk 'BEGIN{FS="<";RS=">"}/</{print $2}' /path/to/textfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Great, It's the best starting point.

thx,
izq.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top