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

Replacing characters 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi Chaps,

Sorry to ask what is probably a silly question, but I'm stumped! Seems easy, I just need to replace square brackets in an ASCII file with round brackets using some sort of grep combination. Any ideas about how to do this?

Thanks for your help,

Simon
 
How about :-

cat test.in | sed -e "s:\[:(:g" -e "s:\]:):g" > test.out

(where test.in is the input file!)

One by one, the penguins steal my sanity.
 
or how about ..

tr &quot;[&quot; &quot;(&quot; < filename1 > filename2
 
or..
Code:
tr &quot;[]&quot; &quot;()&quot; < filename1 > filename2

mbr ;)
 
trunix - much more elegant than my sed, but shouldn't you &quot;escape&quot; the &quot;[&quot; in some way?

The tr works fine for ] -> ) on my solaris server, but if I try to translate the [-> ( it just complains of &quot;Bad String&quot;.

&quot;man tr&quot; shows that a string1 of [something] is a special case, so I've tried various ways of escaping the [ - with no success :-(
One by one, the penguins steal my sanity.
 
Thanks chaps, it works fine. I'll go with the cat command as it's the most baffling-looking, and should impress the boss more! :)
 
ayjaycee.

I tried my tr on SGI and DEC boxes without escaping the [ -which I thought was unusual, but it worked ok. But having worked on several different flavours of unix, I understand that not every solution is satisfactory for every flavour.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top