* Re: (no subject)
[not found] <1995Oct24.201837.21442@newton.ccs.tuns.ca>
@ 1995-10-25 4:00 ` Mark Charette
1995-10-25 4:00 ` Substituting Characters ( ' with '' ) and ( & with and ) Parker Barrington
1995-10-30 5:00 ` (no subject) "Mark Jeffery"
2 siblings, 0 replies; 4+ messages in thread
From: Mark Charette @ 1995-10-25 4:00 UTC (permalink / raw)
Parker Barrington (parkerb@tuns.ca) wrote:
: Now I'm trying to change certain characters in a string. ie
Since you're trying to edit data, typing man -k edit would have brought
up a whole list of interesting things. I've learned more things from man -k
abount different Unices than from any book. One of the entries,
sed (1) - Provides a stream line editor
might be a reasonable place to start.
--
Mark Charette charette@mika.com
MIKA Systems, Inc
17197 N. Laurel Park Dr Suite 115
Livonia, MI 48152
^ permalink raw reply [flat|nested] 4+ messages in thread* Substituting Characters ( ' with '' ) and ( & with and )
[not found] <1995Oct24.201837.21442@newton.ccs.tuns.ca>
1995-10-25 4:00 ` (no subject) Mark Charette
@ 1995-10-25 4:00 ` Parker Barrington
1995-10-27 4:00 ` Stefan Krieghoff
1995-10-30 5:00 ` (no subject) "Mark Jeffery"
2 siblings, 1 reply; 4+ messages in thread
From: Parker Barrington @ 1995-10-25 4:00 UTC (permalink / raw)
To: parkerb
Thank you everyone that answered my question on mailing with a subject
line, I went with: mailx -s "Subject" email@address.here < filename.txt
Now I'm trying to change certain characters in a string. ie
I want
O'Neil
to become
O''Neil
or
John & Martha
to become
John and Martha
I've experimented with tr (translate) but it doesn't seem to allow you
to substitute a single with character several characters. eg.
test=O\'Neil
echo $test | tr '\047' '\047\047'
O'Neil
test="John & Martha"
echo $test | tr '\046' and
John a Martha
How can I substitute a single character with several?
Thank you in advance.
--
Parker Barrington
Technical University of Nova Scotia
Continuing Education Division
http://www.ced.tuns.ca
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Substituting Characters ( ' with '' ) and ( & with and )
1995-10-25 4:00 ` Substituting Characters ( ' with '' ) and ( & with and ) Parker Barrington
@ 1995-10-27 4:00 ` Stefan Krieghoff
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Krieghoff @ 1995-10-27 4:00 UTC (permalink / raw)
: test=O\'Neil
: echo $test | tr '\047' '\047\047'
: O'Neil
: test="John & Martha"
: echo $test | tr '\046' and
: John a Martha
: How can I substitute a single character with several?
Try
test=O\'Neil
echo $test | sed "s/'/''/g"
O''Neil
and
test="John & Martha"
echo "${test}" | sed "s/&/a/g"
John a Martha
:-)) Stefan
_/_/_/_/ _/_/_/ _/ _/_/_/_/ _/_/_/ AEG Atlas Schutz-u. Leittech. GmbH,
_/ _/ _/ _/ _/ _/ _/ Stefan Krieghoff, Abt. LT524
_/_/_/_/ _/ _/ _/_/_/_/ _/_/_/ D-28305 Bremen
_/ _/ _/ _/ _/ _/ _/ +49/421/457-2017 -3886 fax
_/ _/ _/ _/_/_/ _/ _/ _/_/_/ stefan@gatz.atlas.de
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: (no subject)
[not found] <1995Oct24.201837.21442@newton.ccs.tuns.ca>
1995-10-25 4:00 ` (no subject) Mark Charette
1995-10-25 4:00 ` Substituting Characters ( ' with '' ) and ( & with and ) Parker Barrington
@ 1995-10-30 5:00 ` "Mark Jeffery"
2 siblings, 0 replies; 4+ messages in thread
From: "Mark Jeffery" @ 1995-10-30 5:00 UTC (permalink / raw)
Hi,
You should use sed or awk. You can give sed a command to edit a file. For
example the following will substitute this for that in a file fred.txt,
and create newfred.txt as the modified file.
# sed -e 's/this/that/g' fred.txt > newfred.txt
the /g at the end means that the substitute will occur more than once in
a line (do a man sed for more details).
If you need to substitute a special character, you will need to use the \
character before it. For example the following command will substitute /
for \ (useful for moving from UNIX to DOS file specifications!)
# sed -e 's/\//\\/g' fred.csh > fred.bat
The first \/ is the '/' character to replace it, and the \\ is the '\'
character that replaces the '/'. This can be a bit difficult to see, but
it is easy if you practice.
A very useful sequence to use is ^ to signify the beginning of a line, $
the end. The following line will replace './' with 'cp '
# sed -e 's/^\.\//cp ' fred.txt >newfred.txt
An * is a useful wildcard (There are loads more in the manual pages). The
following example will remove from the occurence of the word 'string' to
the end of a line.
# sed -e 's/string*$//' fred.txt >newfred.txt
I don't have a UNIX machine to hand at the moment, so I am sure to have
got something wrong. The key thing is to try things out. You will soon
realise who powerful regular expressions are.
Mark Jeffery
^I ^a^m ^a ^c^o^n^t^r^o^l ^f^r^e^a^k
^ permalink raw reply [flat|nested] 4+ messages in thread