while read l
do
vTimeCreated=`perl -e '@d=localtime ((stat(shift))[9]); printf "%02d-%02d-%04d %02d:% 02d:%02d\n", $d[3],$d[4]+1,$d[5]+1900,$d[2],$d[1],$d[0]' ${l}`
echo "${l} || ${vTimeCreated}" >> ${fPrefx}_Output_Files_${vDate}.txt
done < servername.txt
Using the above code to format date time for each of the filenames present in servername.txt. But it gets stuck in the perl area when huge content is there in the file. Is this a memory problem or is there any other way that we can do the formatting?
Well, you fork and exec perl, a high level language processor, for every line in a shell script, a low level language processor. exec perl once and read the file there.
my desired output in the output file is <filename> || <date>. And the date is not the current date but the date in which the file was created. so i need to do that in the loop. Is there a way to flush the perl or any other better way to do it without using perl
If you have GNU date the following will work
while read file
do
echo "$file || $(date -r $file +"%d-%m-%Y %H:%M:%S")"
done < servername.txt
--Edit--
If not do you have the stat (/usr/bin/stat) command available?
my unix version doesnt support GNU or stat. Is there any other way? or atleast may be flush the perl section after the command is run?
It is nice to find a solution without a fork/exec per line. I recall ksh93 has nice date time built-in functionality.