in reply to perl regex to match newline followed by number and text
This is just a wild guess on my part - I guess that extra new lines meant spacers between these records - but maybe not?:
I guess something very, very simple like this is possible? 3 input lines to one output line?use strict; use warnings; my $line; while (<DATA>) { chomp; if ( (/:$/../^\s*$/) =~ /^\d+$/) #exclude endpoint. { s/\s,\s/,/; $line .= " $_"; } elsif (defined $line) { $line =~ s/^\s*//; print "$line\n"; $line = undef; } } print "$line\n" if defined $line; # just to be sure # all output is done =prints 99~Arun~Kumar~Mobilenum: 1234-567,from Earth Human 98~Mahesh~Babu~Mobilenum: 5678-901,from Earth Human 98~Mahesh~Babu~Mobilenbbb: 5678-901,from Earth Human =cut __DATA__ 99~Arun~Kumar~Mobilenum: 1234-567 , from Earth Human 98~Mahesh~Babu~Mobilenum: 5678-901 , from Earth Human 98~Mahesh~Babu~Mobilenbbb: 5678-901 , from Earth Human
use strict; use warnings; my $input = do {local $/; <DATA>}; my @lines = $input =~ m/(.*\n.*\n.*\n)/g; foreach my $line (@lines) { $line =~ s/\n/ /g; $line =~ s/ , /,/g; print "$line\n"; } =Prints 99~Arun~Kumar~Mobilenum: 1234-567,from Earth Human 98~Mahesh~Babu~Mobilenum: 5678-901,from Earth Human 98~Mahesh~Babu~Mobilenbbb: 5678-901,from Earth Human =cut __DATA__ 99~Arun~Kumar~Mobilenum: 1234-567 , from Earth Human 98~Mahesh~Babu~Mobilenum: 5678-901 , from Earth Human 98~Mahesh~Babu~Mobilenbbb: 5678-901 , from Earth Human
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl regex to match newline followed by number and text
by holli (Abbot) on Jun 01, 2019 at 11:57 UTC | |
by arunkumarzz (Novice) on Jun 01, 2019 at 18:07 UTC | |
by holli (Abbot) on Jun 01, 2019 at 18:29 UTC |