How to read files by Server Creation date wise?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read files by Server Creation date wise?
# 1  
Old 05-05-2013
How to read files by Server Creation date wise?

Hi All,

I would have many files in the server with
xyz*.dat -- Static file name
Physical files:
Code:
xyz1.dat - 01PM
xyz2.dat - 02PM
xyz3.dat - 03PM

In present version we are using
Code:
for f in $file_name
       do     
       fname=`ls $f | grep -v ^'[.]\|[..]'$ | sed s/' '/'\\ '/g`
....
sqlldr ......
....
       done <ireq_id.tmp

This is reading files irrespective of file creation date&time, we need it to pick first come first serve type..

Please advise..
Thanks in Advance.

Last edited by Scrutinizer; 05-05-2013 at 11:39 AM.. Reason: code tags
# 2  
Old 05-05-2013
Get the list of file names in $file_name sorted with time
# 3  
Old 05-05-2013
If there are not too many files in the directory you could do this:
Code:
ls -t $file_name |
while read fname
do
...
done

and don't forget to use double quotes when using referencing $fname:
Code:
some_cmd "$fname"

If there are many file names you could:
Code:
ls -t |
while read fname
do
  case $fname in
    $file_name);;
    *) continue
  esac
   ....
done

# 4  
Old 05-06-2013
Thank you.. hiten.r.chauhan
But how to sort by time at for f in $file_name ## file_name=xyz*.dat

Thank you. Scrutinizer
My main loop is for, that get the physical file name and submit sqlldr and move the file to other locatoin. So how the two options suggested by you would help.
# 5  
Old 05-06-2013
@Dharv you can probably use the lines that are currently in your while loop below the line where fname is being set (I used three dots there ... ). So your main loop would change from a for loop to a while loop. Otherwise you would need to show us more of your script..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy files in order of creation date

Hi everyone :-) I ran into a small issue. I would like to copy some files in the precise order they were created. So the oldest files should be copied first and the newest ones last. I tried cp -r $(ls -1t) ./destination but the files are still not sorted properly. I was thinking, that... (11 Replies)
Discussion started by: officiallyme
11 Replies

2. Shell Programming and Scripting

Bourne returning files based on creation date

I'm wanting to write a bourne shell script that takes in two command line arguments - a directory and a file. With this I want to return a list of files within the directory that are older (based on creation date) than the given file, and print the number of files that have not been listed (they... (4 Replies)
Discussion started by: britty4
4 Replies

3. Shell Programming and Scripting

Extract count of string in all files and display on date wise

Hi All, hope you all are doing well! I kindly ask you for shell scripting help, here is the description: I have huge number of files shown below on date wise, which contains different strings(numbers you can say) including 505001 and 602001. ... (14 Replies)
Discussion started by: VasuKukkapalli
14 Replies

4. UNIX for Dummies Questions & Answers

Select all files in a folder based on creation date (ls command)

Hi All, <Re-posting in Correct group> I'm trying to select all the files in a folder that starts with a particular name format and are created in a gven date range using 'ls' command...but i'm not successful.... Example : I'm trying to see all the text files in a folder who names start... (6 Replies)
Discussion started by: Satya C1
6 Replies

5. Solaris

delete files by date wise

Hi guys, I want to delete files from june 13 to june 30, using rm command can any one tell me the sintax to remove. I ahve hunderd of core files in my /var dir. so i want to clear last month core files. Thanks in Advance.:)) (2 Replies)
Discussion started by: kurva
2 Replies

6. Shell Programming and Scripting

Need to zip the files date wise --urgent Help needed

Hi all, this is my first post, i need to write a script to zip the files with datewise below are the log files. -rw------- 1 root sso 85316156 May 24 22:11 core_test_smservaz_104_104_1243217459_8896 -rw------- 1 root sso 90413304 May 25 22:12 core_test_smservaz_104_104_1243303895_20912... (4 Replies)
Discussion started by: lcschandu
4 Replies

7. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

8. Shell Programming and Scripting

how to read i-node informations (date of creation)

Hi, I'm looking for a way to get the date of creation for a file. Is it possible ? I know that these informations are in the i-node but I don't know how to access them (if the 'find' command can do it with option -ctime, I have reasons to believe in it). Thanks for helping me ! (1 Reply)
Discussion started by: mullmafr
1 Replies

9. UNIX for Dummies Questions & Answers

Moving files based on creation date

Howdy, I'm trying to figure out how to move multiple files based on their creation date. If anyone can enlighten me it would be most appreciated!! Thanks! :D (1 Reply)
Discussion started by: dgoyea
1 Replies
Login or Register to Ask a Question