hi All
I have a file that has 4 lines:
- yesterday's date (mm/dd/yyyy)
- yesterday's day- dd
- yesterday's month- mm
- yesterday's year- yyyy
I want to read this file and place them in variables. how can I do this.
Please help.
thanks in advance!!
KS
hi All
I have a file that has 4 lines:
I want to read this file and place them in variables. how can I do this.
Please help.
thanks in advance!!
KS
you can try a for loop.
I want the lines to be placed in seperate variables... could you kind enough to provide me with the commands?
KS
well in perl you can do it this way.
#! /usr/bin/perl -w
$FILE="test.file";
open FILE, "$FILE" or die "NO GO ($!)";
foreach (<FILE>) { chomp; push @contents, $_; };
foreach (@contents) { print $_,"\n" };
each element of the array contents has a line of the file
so:
$contents[0] has "mm/dd/yyyy"
$contents[1] has "dd"
$contents[2] has "mm"
$contents[3] has "yyyy"
to do it in shell scripting
#! /bin/ksh
i=1
file=test.file
for line in `cat test.file`;do
if [ $i == 1 ]; then
var1=$line
elif [ $i == 2 ]; then
var2=$line
elif [ $i == 3 ]; then
var3=$line
elif [ $i == 4 ]; then
var4=$line
fi
i=$(($i+1))
done
echo VAR1=$var1
echo VAR2=$var2
echo VAR3=$var3
echo VAR4=$var4
both scripts are under the assumption that the file contains the following data
mm/dd/yyyy
dd
mm
yyyy