Hi Anirban
I haven't completely solved the problem - only addressing the DEV field,
but I hope this points you in the right direction!
cheers
Andrew
#!/usr/bin/env perl
use strict;
use warnings;
# NOTE This assumes the space aren't tabs and the columns are aligned
my $input = '
SCGR SC DEV DEV1 NUMDEV DCP STATE REASON
1 0 31 1
SCGR SC DEV DEV1 NUMDEV DCP STATE REASON
2 0 31 1
';
my @input_lines = split /\n/, $input;
foreach my $line (@input_lines) {
next unless $line;
my $dev = substr($line, 10, 15);
$dev =~ s/\s*//g;
unless ($dev) {
$line =~ s/(..........)(.....)/$1UNDEF/;
}
print $line."\n";
}
On Thu, Apr 2, 2015 at 3:43 PM, Anirban Adhikary <[email protected]
> wrote:
> Hi List
>
> I would like to process a file which has the following structure.
>
> SCGR SC DEV DEV1 NUMDEV DCP STATE REASON
> 1 0 31 1
>
> SCGR SC DEV DEV1 NUMDEV DCP STATE REASON
> 2 0 31 1
>
> SCGR SC DEV DEV1 NUMDEV DCP STATE REASON
> 3 0 31 1
>
> SCGR SC DEV DEV1 NUMDEV DCP STATE REASON
> 4 0 31 1
>
> Condition is if any field is empty (In this case DEV and DEV1) those has
> to be replaced by the keyword "NULL". When I am trying to split the line
> based on whitespace
> @elements = split(/\s+/,$line);
> in $element[2] entire blank space is coming upto NUMDEV1. so while
> printing I am not getting the proper output.
>
> How to resolve this problem?
>
> Best Regards
> Anirban.
>
--
Andrew Solomon
Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon