#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    One liner(like sed or perl) for replacing a multiline statement


    I want to replace IP address in my file abc.pm. The pattern is:

    'VT_AGE' =>[
    '192.168.99.77',
    ],


    I can use here if statement to replace this but I want to use some one liners like
    sed -i "s/something/anything/g" file
    or /usr/bin/perl -p -i -e "s/something/anything/g"

    I dont want any help from REGEX side...just can u guys help me whether is it possible or not.
    If Yes then what additional argument I need to add.
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,262
    Rep Power
    1810
    Code:
    perl -p -i -e "s/something/anything/g"
    It's similar to what you did above, but within a perl script use the =~ operator to say you want to perform a regex on the variable to the left of the operator.

    Example:
    Code:
    $string =~ s/\d+/digits/;
    If you are looping over a file, and haven't assiged the current line to some other variable, the current string will be in $_

    Code:
    while (<>) {
       $_ =~ s/\d+/digits/;
    }
    Whenever that is the case, you can drop the default argument and operator because they are assumed.

    Code:
    while (<>) {
       s/\d+/digits/;
    }

IMN logo majestic logo threadwatch logo seochat tools logo