Fw: Variable Replacement Question



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!


.



Relevant Pages

  • Re: quotes in class/id names
    ... In HTML, not if the name consists of only letters, digits, underscores, hyphens, periods, and colons. ... But it's still good practice to use them. ... You *will* need quotes, for example, for URLs that contain slashes, text field values that include spaces, and so forth. ...
    (alt.html)
  • Re: New Google Algo Change
    ... site has the same meta title and page header as 'Blue Suede Shoes'. ... to number 800 for the title search 'Blue Suede Shoes'. ... I also tried without quotes searching with Blue-Suede-Shoes ... with hyphens. ...
    (alt.internet.search-engines)
  • Re: How to find total MB of a directory plus all subdirectories
    ... quotes. ... but all of the subdirectories are ... multi worded without any hyphens, and du didn't have any problem ... without hyphenated words, and yet has no problem with all the ...
    (Fedora)