in reply to Re: perl regex to match newline followed by number and text
in thread perl regex to match newline followed by number and text

Hello Grandfather,

The example you have provided is little bit different from my issue. I have updated my question with some sample data. Could you please have a look at it?

Thanks in advance
  • Comment on Re^2: perl regex to match newline followed by number and text

Replies are listed 'Best First'.
Re^3: perl regex to match newline followed by number and text
by poj (Abbot) on May 31, 2019 at 15:48 UTC
    #!/usr/bin/perl use strict; my $record; while (<DATA>){ s/\n/ /; if (/^\d+~/){ $record =~ s/ +$//; # trim trailing spaces printf "%s\n",$record if ($record); $record = $_; } else { $record .= $_; } } $record =~ s/ +$//; printf "%s\n",$record if ($record); __DATA__ 99~Arun~Kumar~Mobilenum: 1234-567 , from Earth Human 98~Mahesh~Babu~Mobilenum: 5678-901 , from Earth Human
    poj
      Thank you everyone for your suggestions, poj's method worked for me right now.
Re^3: perl regex to match newline followed by number and text
by Marshall (Canon) on Jun 01, 2019 at 06:54 UTC
    I see your Edit 1.
    Can you enclose the data in code tags so that we can see the new lines?
    The better the problems is described, the better the result will be. Your regex doesn't make much sense to me.

     s/((\n)([^0-9])+(-)*(Aa-Zz)*)|((\n)(\d{3})(-)*(Aa-Zz)*)/$2$3/g
    My brain hurts.