Fw: Variable Replacement Question
- From: "Brian K. White" <brian@xxxxxxxxx>
- Date: 14 Feb 2006 20:58:49 -0500
Resending. I sent it 6 hours ago but never made it I just noticed...
----- Original Message -----
From: "Brian K. White" <brian@xxxxxxxxx>
To: <scomsc@xxxxxxx>
Sent: Tuesday, February 14, 2006 3:04 PM
Subject: Re: Variable Replacement Question
----- Original Message -----
From: "Jeff Hyman" <scolist@xxxxxxxxxx>
Newsgroups: comp.unix.sco.misc
To: <distro@xxxxxxx>
Sent: Tuesday, February 14, 2006 1:23 PM
Subject: Variable Replacement Question
Hello all,
COMPANY='JOE'S TRUCKING CO. ' <== Problem (3 hyphens in one line)
^=== when using hyphen as part of variable
COMPANYx='JOES TRUCKING CO. ' <== Not a problem, theres no hyphen in
JOES
ADDRESS='123 MAIN ST. '
Couple of requirements:
1. The hyphens enclosing the entire variable MUST be used as displayed
above.
Open/Closed quotation marks cannot be used... single or double.
2. Objective is to change JOE'S ==> JOES as in COMPANYx above
WITHOUT modifying the the first and last hyphens.
I'm hoping there's a simple solution... but my noodle is cooked.
Any input would be greatly appreciated.
- Jeff Hyman
I think you need to re-post that.
I don't even see one hyphen and don't know what the problem would be if
there were.
... ah, you mean single forward quotes?
easy, but somethings are still not clear, but I'll assume that this is a
file or data stream that you have to process that has lines that look like
that
and not a script you can edit directly where the problem is merely how to
handle variables containing tricky data.
In other words, these are not variables (at least not at this point), they
are lines of text. (which will probably be variables in some later step.)
One way might be to strip all quotes, then add the leading & trailing back
on.
awk -F= -v q=\' '{gsub(q,"",$2);print $1"="q$2q}' in.txt >out.txt
or
myprog |awk -F= -v q=\' '{gsub(q,"",$2);print $1"="q$2q}' >out.txt
If you meant something else and you are inside a script and there are
variables whose contents contain the quotes, then this will do it, uglily:
COMPANY=\'`echo "$COMPANY" |tr -d "'"`\'
you only need the 2nd variable COMPANYx if you want to preserve the
original, and both of these do preserve the trailing spaces.
I'd cut & paste that 2nd one if you need it. It has both forward and back
single quotes in it and some fonts do not show the difference very well
just by eyesight.
Brian K. White -- brian@xxxxxxxxx -- http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
.
- Prev by Date: Re: Win2k Ras/VPN and a SCO Unix Machine and some difficulty getting to the SCO Machine [LONG]
- Next by Date: Re: SCO crud sub database dirt
- Previous by thread: Win2k Ras/VPN and a SCO Unix Machine and some difficulty getting to the SCO Machine [LONG]
- Next by thread: claudiangus54@hotmail.com
- Index(es):
Relevant Pages
|