Mailing List Archive


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

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



On Mon, 5 Aug 2002 12:43:44 -0400
Viktor Pavlenko <vvp@example.com> wrote:

> If your file is named crs.txt, do
> 
> $ perl -pe 'BEGIN{$/=""} s/\n(?=\D)/ /g' < crs.txt
> 
> Well I wanted something like
> 
> 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?
>
The latter two, with the default record separator,
read each line from crs.txt into "$_" one by one.
Then, $_ is terminated with "\n" and never matches
up with the regexes like /\n(\D)/ or /\n(?=\D)/.
When you replace "$/" with "" as you did with the
first solution, the lines in the file are concatenated
into one and are read into "$_" at a time. Then it
matches the regexes.

If you don't like BEGIN, the package constructor,
how about this:

$ perl -0777pe 's/\n(?=\D)/ /g' crs.txt

-- 
SAKUMA Junichi <jun@example.com>
Key fingerprint = 199D 03E9 E7C0 CC66 E2D9  AD3F CB2E F76F 8AD9 FC62


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links