in reply to A text replacement question

Try a one-liner.
perl -pni.bak -e "s/1 (\w{1,2}v\w{1,2})/2 $1/" filename
and call that for every file.
Under windows you can say:
c:\> for %f in (*.html) do perl -pni.bak -e "s/1 (\w{1,2}v\w{1,2})/2 $ +1/" %f
I am not sure how to achieve the same under linux.
Note the %f is a shell-wildcard, not a perl hash.


holli, /regexed monk/


Update:
Silly me. I had in mind -p just prints $_ but it assumes loop like -n but print line also, like sed.
Thanks for clarifiying Animator.

Update:
Animator got me to read you're question more carefully. I think your more after something like this:
perl -pi.bak -e 's/\b(\w{1,2}v\w{1,2})\b/g<a href="$1.html">$1<\/a>/" +filename
Added a /g modifier just in case there can be more occurances in one line.

Replies are listed 'Best First'.
Re^2: A text replacement question
by Animator (Hermit) on Feb 15, 2005 at 12:52 UTC

    Hmm, I'm not sure if that's exactly what he wants.. I think he is looking to add it multiple times (which would ofcourse only mean that the replacement part of the s/// changes into $1$1$1... (or $1 x 3) (for example).

    simple, you should be able to use *.html as filename...

    Small note, why do you use '-pn'? -p: print, -n: don't print... -p should do just fine

      hmm the more ive read on this the more im unsure of what the solution would look like. somewhere im expecting to see something that for each
      $1= *v* <v> gives code1 $1 code2 $1 and then so on for each *v* in each file... - (steamerboy)
Re^2: A text replacement question
by steamerboy (Initiate) on Feb 15, 2005 at 14:23 UTC
    well the 'names' i mentioned arent links - theyre names for values that get recorded. The code for the checkboxes is like
    (code value=1 name =xvx) (code value=2 name= xvx)... and so on for each checkbox. So the idea is for the code to get any ? v ? and replace it with itself embedded in the code - saving me 500 years of time! Thanks for the help - much aprreciated! (steamerboy)
      It would be much easier if you gave real examples of the input and the expected output...
        Looking at one of the files you would see would see;

        AAvIY
        AAvT
        AAvY
        AAvHH
        TvHH
        ZHvTH
        DHvZH

        ...
        and many, many more!
        And what im expecting as output is

        (for 13v13 - im using letters in my code though!)
        <INPUT TYPE=radio NAME=13v13 VALUE='' CHECKED>three & six
        weak<INPUT TYPE=radio NAME=13v13 VALUE=1><INPUT TYPE=radio NAME=13v13 VALUE=2><INPUT TYPE=radio NAME=13v13 VALUE=3><INPUT TYPE=radio NAME=13v13 VALUE=4><INPUT TYPE=radio NAME=13v13 VALUE=5><INPUT TYPE=radio NAME=13v13 VALUE=6><INPUT TYPE=radio NAME=13v13 VALUE=7>strong


        so for AAvBB i'd want to get; weak<INPUT TYPE=radio NAME=AAvBB VALUE=1> <INPUT TYPE= radio NAME=AAvBB VALUE=2>....<INPUT TYPE radio NAME=AAvBB VALUE=5>strong


        . ideally id like the regex to operate on xvx but not NAME=xvx. Hope that helps