jayjaybigs
IS-IT--Management
Hello All,
I have a Perl Code as below. Because my input file is so large, hence Perl code modification will take for ever. However, I need to convert this Perl code to Unix Script. Please Help to write unix script that will perform the same job as the Perl code below. Thanx a bunch everyone for your time.
NOTE: The perl code below take one record from a file put it into array, modify certain element of the array and put the record back into a new file.
#!/usr/bin/perl
use strict ;
#use warnings ;
use Date::Manip ;
my (@input) ;
my ($input_record) ;
my ($output_file);
my ($input_file);
my ($array_record);
my (@array_record);
my (@array) ;
my ($name);
my ($lchar);
my ($date);
my (@array_file);
my (@names);
my ($new_record);
$input_file = "ytd_100.txt";
$output_file = "ytd_100.dat";
#check input file
(-e $input_file) || die ("input file does not exist \n") ;
open(INPUT, "$input_file") || die ("could not open infile\n");
open(OUTPUT, ">$output_file") || die ("could not open outfile \n") ;
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;
#Start Modifying Here
if (( $array[4] == 1) && ( $array[5] eq "A")) {
$array[4] = "BCGEU 2" ;
$array[5] = "REGULAR FT"
}
if (( $array[4] == 1) && ( $array[5] eq "C")) {
$array[4] = "BCGEU 2" ;
$array[5] = "REGULAR PT"
}
if (( $array[4] == 1 ) && ( $array[5] eq "F")) {
$array[4] = "BCGEU 2" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 1 ) && ( $array[5] eq "E")) {
$array[4] = "BCGEU 2" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 2) && ( $array[5] eq "A")) {
$array[4] = "BCGEU 1" ;
$array[5] = "REGULAR FT"
}
if (( $array[4] == 2) && ( $array[5] eq "C")) {
$array[4] = "BCGEU 1" ;
$array[5] = "REGULAR PT"
}
if (( $array[4] == 2) && ( $array[5] eq "F")) {
$array[4] = "BCGEU 1" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 4) && ( $array[5] eq "A")) {
$array[4] = "EXCLUDED" ;
$array[5] = "REGULAR FT"
}
if (( $array[4] == 4) && ( $array[5] eq "C")) {
$array[4] = "EXCLUDED" ;
$array[5] = "REGULAR PT"
}
if (( $array[4] == 4) && ( $array[5] eq "F")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 5) && ( $array[5] eq "A")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SUPPORT FT"
}
if (( $array[4] == 5) && ( $array[5] eq "C")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SUPPORT PT"
}
if (( $array[4] == 5) && ( $array[5] eq "F")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SUPPORT ST"
}
$array[3] = " ";
chomp(@array) ;
#$array[12]=sprintf("%.2f", $array[12]);
$array[12]=$array[12]*0.010 ;
#$stop modifying here
$new_record = join ',', @array;
print OUTPUT "$new_record\n";
}
close (INPUT) ;
close (OUTPUT) ;
I have a Perl Code as below. Because my input file is so large, hence Perl code modification will take for ever. However, I need to convert this Perl code to Unix Script. Please Help to write unix script that will perform the same job as the Perl code below. Thanx a bunch everyone for your time.
NOTE: The perl code below take one record from a file put it into array, modify certain element of the array and put the record back into a new file.
#!/usr/bin/perl
use strict ;
#use warnings ;
use Date::Manip ;
my (@input) ;
my ($input_record) ;
my ($output_file);
my ($input_file);
my ($array_record);
my (@array_record);
my (@array) ;
my ($name);
my ($lchar);
my ($date);
my (@array_file);
my (@names);
my ($new_record);
$input_file = "ytd_100.txt";
$output_file = "ytd_100.dat";
#check input file
(-e $input_file) || die ("input file does not exist \n") ;
open(INPUT, "$input_file") || die ("could not open infile\n");
open(OUTPUT, ">$output_file") || die ("could not open outfile \n") ;
@array_file = <INPUT> ;
foreach $array_record (@array_file){
@array = split (",", $array_record) ;
#Start Modifying Here
if (( $array[4] == 1) && ( $array[5] eq "A")) {
$array[4] = "BCGEU 2" ;
$array[5] = "REGULAR FT"
}
if (( $array[4] == 1) && ( $array[5] eq "C")) {
$array[4] = "BCGEU 2" ;
$array[5] = "REGULAR PT"
}
if (( $array[4] == 1 ) && ( $array[5] eq "F")) {
$array[4] = "BCGEU 2" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 1 ) && ( $array[5] eq "E")) {
$array[4] = "BCGEU 2" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 2) && ( $array[5] eq "A")) {
$array[4] = "BCGEU 1" ;
$array[5] = "REGULAR FT"
}
if (( $array[4] == 2) && ( $array[5] eq "C")) {
$array[4] = "BCGEU 1" ;
$array[5] = "REGULAR PT"
}
if (( $array[4] == 2) && ( $array[5] eq "F")) {
$array[4] = "BCGEU 1" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 4) && ( $array[5] eq "A")) {
$array[4] = "EXCLUDED" ;
$array[5] = "REGULAR FT"
}
if (( $array[4] == 4) && ( $array[5] eq "C")) {
$array[4] = "EXCLUDED" ;
$array[5] = "REGULAR PT"
}
if (( $array[4] == 4) && ( $array[5] eq "F")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SHORT TERM"
}
if (( $array[4] == 5) && ( $array[5] eq "A")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SUPPORT FT"
}
if (( $array[4] == 5) && ( $array[5] eq "C")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SUPPORT PT"
}
if (( $array[4] == 5) && ( $array[5] eq "F")) {
$array[4] = "EXCLUDED" ;
$array[5] = "SUPPORT ST"
}
$array[3] = " ";
chomp(@array) ;
#$array[12]=sprintf("%.2f", $array[12]);
$array[12]=$array[12]*0.010 ;
#$stop modifying here
$new_record = join ',', @array;
print OUTPUT "$new_record\n";
}
close (INPUT) ;
close (OUTPUT) ;