Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] sed or perl script help please . . .



>>>>> "SJ" == SAKUMA Junichi <jun@example.com> writes:

    >> 
    >> perl -pe 's/\n(\D)/ $1/sg' < crs.txt
    >> or
    >> perl -pe 's/\n(?=\D)/ /sg' < crs.txt
    >> 
    >> but they don't work. Any ideas why?
    >> 
    SJ> The latter two, with the default record separator,
    SJ> read each line from crs.txt into "$_" one by one.
    SJ> Then, $_ is terminated with "\n" and never matches
    SJ> up with the regexes like /\n(\D)/ or /\n(?=\D)/.

Did you notice the s modifier in the samples above?

In the following example $_ is not terminated by the first \n and all
replacements are made:

$ perl -pe 's/\n/ /sg' < crs.txt

This works too, through all lines:

$ perl -pe 's/o/O/sg' < crs.txt

So, s modifier means: you can treat it as a single line as long as you
don't mess with the record separator...

Viktor


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links