radekc has asked for the wisdom of the Perl Monks concerning the following question:

Letter A = "AAA" Letter B = "BBB" perl -p -e 's/(Letter A \=)(.*\")(\n+)(Letter B \=)/$1$2$3$4/g' text

How can group these words? Seems the problem is after \n

Replies are listed 'Best First'.
Re: How can group these strings
by JavaFan (Canon) on Apr 24, 2012 at 07:17 UTC
    The problem is that you are reading line by line (-p), but want to apply a regexp on multiple lines.

    Pick another delimiter. Perhaps you want the -0777 command line switch (but I don't know what else is in the file text)

Re: How can group these strings
by Anonymous Monk on Apr 24, 2012 at 06:40 UTC

    How can group these words? Seems the problem is after \n

    What does that mean? Please specify with code, use use Data::Dump; to generate sample data

    my $input = "blah Letter A blah ..\n bla \n"; my $wantedOutput = " .... what you want here ... \n";
      perl -p -e 's/(.*)(\n)(.*)/$1$3/g' text
      --Thiru "There is a solution for all problems but we need to find a direction"
Re: How can group these strings
by 2teez (Vicar) on Apr 25, 2012 at 02:04 UTC

    If your intention was just to group this strings, then chomp in a perl one-liner could do the job.
    Case (a):

    perl -pe "chomp;" text.txt
    this is equalvalent to:
    LINE: while (defined($_ = <ARGV>)) { chomp $_; } continue { die "-p destination: $!\n" unless print $_; }

    Case (b):

    perl -ne "chomp;print" text.txt

    which is equalvalent to:
    LINE: while (defined($_ = <ARGV>)) { chomp $_; print $_; }

    Hope this helpss -:)