V
Vahid
Hi all,
Is it possible to parse two colon delimited files and merge one field
from one of the files with the other file? For example if I want to
merge the second field (b) of the first file with the contents of
a:b:c:d with the third field of the second file with the contents of
e:f:g:h, I would get e:f:b:h. I came up with the following but don't
know where to add the parser for the second file?
sub mkShadow() {
open (SHADOWfh, "<$SHADOW") || die "Can not open the file:
$SHADOW. $!\n";
open (PASSWDfh, "<$PASSWD") || die "Can not open the file:
$PASSWD. $!\n";
open (XSHADOWfh, ">$XSHADOW") || die "Can not open the file:
$XSHADOW. $!\n";
@lines = <SHADOWfh> ;
### @linesX = <XSHADOWfh> # this is what I want
foreach $line (@lines) {
## what goes here?
# Skip comments
next if (m/^#/);
# Skip blank lines
next if (m/^\s*$/);
($username,$pass,$lastchange) = split /:/, $line;
## what goes here?
$x_lastupdate = ($lastchange*86400);
#
print $XSHADOWfh ("username: %s password: %s lastupdate: %d
\n", \
$username,$pass,$x_lastupdate) ;
} # for each
close $SHADOWfh;
close $XSHADOWfh;
close $PASSWDfh;
@args = ("pwdck", "-y", "ALL");
system(@args) == 0 or warn "System @args failed: $?";
}
Thank you very much,
Is it possible to parse two colon delimited files and merge one field
from one of the files with the other file? For example if I want to
merge the second field (b) of the first file with the contents of
a:b:c:d with the third field of the second file with the contents of
e:f:g:h, I would get e:f:b:h. I came up with the following but don't
know where to add the parser for the second file?
sub mkShadow() {
open (SHADOWfh, "<$SHADOW") || die "Can not open the file:
$SHADOW. $!\n";
open (PASSWDfh, "<$PASSWD") || die "Can not open the file:
$PASSWD. $!\n";
open (XSHADOWfh, ">$XSHADOW") || die "Can not open the file:
$XSHADOW. $!\n";
@lines = <SHADOWfh> ;
### @linesX = <XSHADOWfh> # this is what I want
foreach $line (@lines) {
## what goes here?
# Skip comments
next if (m/^#/);
# Skip blank lines
next if (m/^\s*$/);
($username,$pass,$lastchange) = split /:/, $line;
## what goes here?
$x_lastupdate = ($lastchange*86400);
#
print $XSHADOWfh ("username: %s password: %s lastupdate: %d
\n", \
$username,$pass,$x_lastupdate) ;
} # for each
close $SHADOWfh;
close $XSHADOWfh;
close $PASSWDfh;
@args = ("pwdck", "-y", "ALL");
system(@args) == 0 or warn "System @args failed: $?";
}
Thank you very much,