Training, Open Source
computer languages


PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Replacing parts of lines

Posted by TedH (TedH), 2 February 2008
Hi Graham, how's everything there?
I have a file with hundreds of lines and double that in "parenthesis content"

Each line = somekindoftext (aaa) (bb)

Each one is different. I'm trying to get rid of all the parenthesis and everything in them.

I've tried this to no avail, so must be missing somethng.

Code:
## Replace all parenthesis and everything in them
$file="loc.txt";
$first=" (";
$last=")";
$blank="";

open( CURRENTFILE, "$file");
 while ( <CURRENTFILE> ) {
  s/$first(.*)$last/$blank/;
 }
close(CURRENTFILE);


Hope you can help,
Cheers - Ted

Posted by KevinAD (KevinAD), 2 February 2008
If I may provide assistance:


## Replace all parenthesis and everything in them
$file="loc.txt";
$first=" (";
$last=")";
$blank="";

open( CURRENTFILE, "$file");
 while ( <CURRENTFILE> ) {
  s/ \Q$first\E (.*?) \Q$last\E /$blank/gx;
  print;
 }
close(CURRENTFILE);


Ask questions if needed.

Posted by TedH (TedH), 2 February 2008
Thanks Kevin - Ted



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


WELL HOUSE CONSULTANTS LTD.: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho