Replace word

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mass845
    New Member
    • Sep 2006
    • 1

    Replace word

    Hi there. Need some experts here. I have a file that contains a few unrelated words such as "[IMAGE]", "[FORM NOT SHOWN]","[TABLE NOT SHOWN]" words in a few locations. I have try to search and delete all of these words. For example:

    A file contains:
    [IMAGE] [FORM NOT SHOWN] Virtualization allows a platform to run multiple operating systems and applications in independent partitions or "containers ." [TABLE NOT SHOWN] One physical compute system can function as multiple "virtual" systems. [IMAGE] Vanderpool Technology can help improve future.

    My simple code like this:
    Code:
    $_ =~ tr/^[IM.+AGE]$/ /d;
    I get:
    FOR NOT SHOWN
    Virtualization allows a platform to run multiple operating systems and applications in independent partitions or "containers " One physical compute system can function as multiple "virtual" systems Vanderpool Technology can help improve future

    which all the I,M,A,G,E, and full-stop gone.

    I want:
    Virtualization allows a platform to run multiple operating systems and applications in independent partitions or "containers ." One physical compute system can function as multiple "virtual" systems. Vanderpool Technology can help improve future.

    Plese let me know if you have solution on it.

    Best wishes,
  • thurban
    New Member
    • Sep 2006
    • 6

    #2
    Hi,

    How about this:
    Code:
    my $string = '[IMAGE] [FORM NOT SHOWN] Virtualization allows a platform to
     run multiple operating systems and applications in independent partitions
     or "containers." [TABLE NOT SHOWN] One physical compute system can
     function as multiple "virtual" systems. [IMAGE] Vanderpool Technology can
     help improve future';
    
    $string =~ s/\[[A-Z\s]+\]\s//ig,
    
    
    print $string;
    This would search for any occurrence of "[SOME TEXT IN UPPERCASE] " and delete it.

    Comment

    Working...