Braces within a string

  • Follow


I have a problem where I have a fixed field (i.e., $12) that contains either
a string (i.e., JOE) or a string enclosed in braces (i.e., {JOE IS NOT
HERE}) I am having trouble using gsub or gensub in awk to change the field
to something I can use. I can't access the filed properly if there is
multiple words in the field.  Is there a good way of changing the braced
string with a constant? (i.e., {JOE IS NOT HERE} changes to TEST)


0
Reply Jim 7/9/2003 4:38:07 AM

In article <P_MOa.189284$nr.8544198@twister.southeast.rr.com>,
Jim <jshelby@nc.rr.com> wrote:
>I have a problem where I have a fixed field (i.e., $12) that contains either
>a string (i.e., JOE) or a string enclosed in braces (i.e., {JOE IS NOT
>HERE}) I am having trouble using gsub or gensub in awk to change the field
>to something I can use. I can't access the filed properly if there is
>multiple words in the field.  Is there a good way of changing the braced
>string with a constant? (i.e., {JOE IS NOT HERE} changes to TEST)
>
>

how about something like this:

sub(/[{][^}][^}]*[}]/,"TEST",$0)


Chuck Demas

-- 
  Eat Healthy        |   _ _   | Nothing would be done at all,
  Stay Fit           |   @ @   | If a man waited to do it so well,
  Die Anyway         |    v    | That no one could find fault with it.
  demas@theworld.com |  \___/  | http://world.std.com/~cpd
0
Reply demas 7/9/2003 11:07:15 PM


1 Replies
297 Views

(page loaded in 0.032 seconds)

Similiar Articles:













7/23/2012 5:30:44 PM


Reply: