how to find file time using ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to find file time using ksh
# 1  
Old 09-29-2008
how to find file time using ksh

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..
# 2  
Old 09-29-2008
You have a space between filetime and the equals sign. Get rid of that space.
# 3  
Old 09-29-2008
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

Last edited by manmeet; 09-29-2008 at 06:22 PM..
# 4  
Old 09-29-2008
Quote:
Originally Posted by manmeet
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
Quote:
filetime=`cat $InputfileName-$mdt.csv | awk '{print $7 }'`
or
Quote:
filetime=`awk '{print $7 }' $InputfileName-$mdt.csv`
?
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
Quote:
filetime=`ls -l $InputfileName-$mdt.csv | awk '{print $7 }'`
?
/Lakris
# 5  
Old 09-30-2008
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.

-rw-r----- 1 heyhytt65 dshew 144 Sep 29 14:48 'addr_interface'-08_09_29.csv

in this 16:35 is time and it is the 7th value in the file description... so that is what i am trying to fetch ...
# 6  
Old 09-30-2008
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.

Best regards,
Lakris
# 7  
Old 09-30-2008
That is ok Lakris...My code is working now ...Thanks Anyways...nad yes there is actually codes in filename
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh to find specific infomation in a delimited file

I am using ksh and looking for a simple way to print the entire row when a specific column contains specific infomation. I know I can use grep to find the information however I can not specify the column. File test.txt contents: Abc,223,223,223 efg,354,224,774 hij,354,2230,773... (5 Replies)
Discussion started by: oldman2
5 Replies

2. Shell Programming and Scripting

How do i find a file with the current time stamp in it??

I want to find a file using find or any utility having the current date time stamp..... I have an alternate way to do that.... but that is too way out of logic... so looking out something with find itself (5 Replies)
Discussion started by: nikhil jain
5 Replies

3. Shell Programming and Scripting

Find more then 1000 file at a time

Dear All, The need to found more than 1000 file are available in particular directory or not .That more than 1000 file stored in file.txt . i tried with locate & find command .But i can't get.pls post if any other option (1 Reply)
Discussion started by: kpoobathi
1 Replies

4. Shell Programming and Scripting

find file creation time

Hello folks, I have a file, but it change every seconds, i use stats command to check its creation time, but it shows access,modify and change time same. Is there any other way to see the file creation date/time? Thanks (2 Replies)
Discussion started by: learnbash
2 Replies

5. Shell Programming and Scripting

ksh - AIX: get epoch time/age for a file?

Hi, (AIX 5.1) Is there any way to find the epoch timestamp for a file without having to use fancy perl (or similar) scripts? If anyone knows of a way to do this using just ksh commands it would be appreciated. (It also appears I don't have the stat command available). Alternatively is... (3 Replies)
Discussion started by: b0bbins
3 Replies

6. Shell Programming and Scripting

ls -e to find out File modification time in secs

Hi All, I would like to know the file modification time till seconds in Unix. So I tried ls -e and it worked fine. This Solaris 5.10 -rw-rw-r-- 1 test admin 22 Sep 12 11:01:37 2008 test_message But I am not able to run the same command in SOlaris 5.6 and also in AIX/HP Is there... (3 Replies)
Discussion started by: rahulkav
3 Replies

7. Shell Programming and Scripting

Find the file names from date/time: Need help

Hi All, I really need help in figuring out how to determine the filenames from the time that is specified as parameter. The script should take as input - the start time and end time in minutes and also start date and end date. Example: reporter.sh -instance Instance_Name -startTime 13:10... (0 Replies)
Discussion started by: chiru_h
0 Replies

8. Shell Programming and Scripting

Find/replace to new file: ksh -> perl

I have korn shell script that genretaets 100 file based on template replacing the number. The template file is as below: $ cat template file number: NUMBER The shell script is as below: $ cat gen.sh #!/bin/ksh i=1; while ((i <= 100)); do sed "s/NUMBER/$i/" template > file_${i} ((... (1 Reply)
Discussion started by: McLan
1 Replies

9. HP-UX

KSH to find a ORA error in a log file

Hi: i have writen a script that needs a finishing Pourpouse is to find a particular error in a file after we enter file name and the return msg would describe if >there is a error -> "Contact DBA" if there is no oracle error ->"No ora error found." for the same i have written a script... (6 Replies)
Discussion started by: techbravo
6 Replies

10. UNIX for Dummies Questions & Answers

Command to find last time file was opened

New to unix .. Is there a simple command or utility that will tell me when the last time a file was opened/used? (3 Replies)
Discussion started by: sbr262
3 Replies
Login or Register to Ask a Question