Hi ,
i need to extract only time for a file and i am using following code for this..
while read record1
do
SQLQuery=`echo $Record1 | awk '{printf $0 }'`
InputfileName=`echo $Record1 | awk '{printf $8 }'`
ColumnNamesSPcomma=`echo $Record1 | awk '{printf $4 }'`
filetime =`echo $InputfileName-$mdt.csv | awk '{print $7 }'`
in here. first of all i'm extracting some column name from a SQL query and using it as output file name that is
InputfileName=`echo $Record1 | awk '{printf $8 }'`
and output file name is InputfileName-$mdt.csv
where mdt is variable name having current system date
now i need to time for this output file so i used
filetime =`echo $InputfileName-$mdt.csv | awk '{print $7 }'`
when i tried to echo filetime i am getting an error that filetime not found.
can anybody fix my code and help regarding thisASAP..
Many Thanks in advance..
Hi Perderado .....thanks a lot ...but i still have problem.....when i tried to echo the filetime ...it is showing nothing on the terminal screen...actually the thing is first i need to check if $InputfileName-$mdt.csv file exists or not if yes then i need its time for the last modification and i have code like this..
if [ -s $InputfileName-$mdt.csv ]
then
echo "$InputfileName-$mdt.csv exists"
filetime=`echo $InputfileName-$mdt.csv | awk '{print $7 }'`
echo $filetime
Hi,
I am not sure exactly what the string $InputfileName-$mdt.csv would look like, could You give us an example? But to me it looks as if You are trying to print the 7th field of the string, and unless it has a lot of spaces in it, maybe the 7th field is empty? Maybe You mean to do
or
?
What I mean is You want to get the 7th field of the contents/the line in that file? Just an idea...
Or maybe You want
Hi Lakris ,
Thanks for ur help..
actually $InputfileName-$mdt.csv is file name where InputfileName is a variable having some values say table_name and mdt is current system date.
so by using filetime=`echo $InputfileName-$mdt.csv | awk '{print $7 }'`
i am trying to fetch time when last time file was modified . when we type ls -lt then 7th value is the time ...for e.g.
I am sorry, but that doesn't make very much sense to me. I guess You must read up on some very basic command line operations.
If You echo a string (such as contained in a variable) You will get the string, not a line from a directory listing
And do You actually have quotes in the filename?
And time is the 8th value, right?
You know, You would make it easier for people to help if You posted (copy/paste) some actual code and runtime output from Your attempts.