Getting all the files modified today & store the names in a variable as , separated


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting all the files modified today & store the names in a variable as , separated
# 1  
Old 04-24-2009
Getting all the files modified today & store the names in a variable as , separated

Hi all,

I have a question. I have a folder. I want to find the list of files that are modified today and store all those file names in a variable as comma separated values. I thought of using
"find . -mtime 0" command to find the list of files modified today. Also to get those values of file name stored in a variable, I thought of using
"find . -mtime 0 | awk '{print $1}'" command. But 1 value is hard coded in that. I need to know how many outputs coming out of "find . -mtime 0" command so that i can dynamically vary my print statement in awk.

Any help on this.

Thanks in advance.

Thanks,
Ananthi.U
# 2  
Old 04-24-2009
Which shell you are using (exact version if possible)?
# 3  
Old 04-24-2009
You could try

Code:
var=$(find . mtime -1d | tr '\n' ',')

or

Code:
var=$(find . mtime -1d |perl -pi -e 's/\n/,/g')

Only issue with those is it will put a , on the end of the string.

Perhaps you could then just replace the end , with sed or something
# 4  
Old 04-24-2009
Thanks for ur reply...

But when i execute both the exp, i m getting "find: invalid predicate `-1d'" error.... Smilie what would be the reason?
# 5  
Old 04-24-2009
Depends on your shell and find version.

I was just doing that on solaris in sh.

try your original -mtime 0
# 6  
Old 04-24-2009
Thank u very much... It s like a magic...

I tried with the following command

var=$(find . -mtime 0 | tr '\n' ',')

It gives me the result ".,./WS2003-WindowsMedia-BD.doc,./avcodec_sample.cpp," as these are the two files modified today in the server path.

Can u explain me how this command works?

Also what is the reason for "." coming as first name then followed by the file names?
# 7  
Old 04-24-2009
If you don't want the trailing ,:

Code:
files="$(find . -mtime -1|paste -sd, -)"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace & with and in tab separated file?

Hi, I have a tab separated. I want to replace all the "&" in 8th column of the file with "and" .I am trying with awk -F, -vOFS=\\t '{$8=($8=="&")?"and":$8}1' test> test1.txt My file is abc def ghk hjk lkm hgb jkluy acvf & bhj hihuhu fgg me mine he her go went has has & had hgf hgy ... (1 Reply)
Discussion started by: jagdishrout
1 Replies

2. Shell Programming and Scripting

How to store files names from a directory to an array

Hi I want to store the file names into an array. I have written like this but I am getting error. declare -A arr_Filenames ls -l *.log | set -A arr_Filenames $(awk '{print $9}') index=0 while (( $index < ${#arr_Filenames })); do Current_Filename=${arr_Filenames} ... (5 Replies)
Discussion started by: dgmm
5 Replies

3. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

4. Shell Programming and Scripting

Parse text file in shell & store to variable

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is in constant. And there is only 1 BRXXX in a file at a given time. .txt file: BR276828... (1 Reply)
Discussion started by: script2010
1 Replies

5. Shell Programming and Scripting

script to store comma separated values in different variables

Hello friends, I need ur help.I want to write a script. The script should read contents from a file namely xyz. e.g xyz abcd,1234,efgh,7854378 dhnsa,dsakjkdl,43432,ZXDsa the script should store comma (,) seperated values in different variables. Once pointer will reach end of line (\n), it should... (1 Reply)
Discussion started by: akhtar.bhat
1 Replies

6. Shell Programming and Scripting

Find files older then today & display with timestamp info

Small query- I want to do some operation on all the files older then today. Before I do that operation, i want to verify if the command works properly or not. Surprisingly, the command below returns me file, which are created today - find /mrk_archive/PG/ftp/incomming/gbs/2008 -type f... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

7. Shell Programming and Scripting

Getting modified time & filename only

Hi, When we use "ls -l" we are getting like below, -rw-r--r-- 1 mdskl mds 4161479 Apr 12 14:57 VTTF2008.20080412145748.cc But i need only modified time and filename only like below, Apr 12 14:57 VTTF3008.20080412145748.cc Thanks-:) Senthil (4 Replies)
Discussion started by: senthil_seera
4 Replies

8. UNIX for Advanced & Expert Users

Find and store files based on FileName and Modified Time

Hi, I am currently using the following command: files=(ls enuCPU??.????.exp ntuCPU??.????.exp) I need to now change the commmand to store the file names of files that have been modified before datetime equal to say '02/16/2008 20:30:00' What could I use? (2 Replies)
Discussion started by: edisonantus
2 Replies

9. Shell Programming and Scripting

List Files & Folders created/modified

Hello people, I want to list the files & folders created/modified since a particular date say June 2006. I know I can list recursively thru the folders and use awk to extract the date column to get the desired output. Just wanted to check whether there is an easier way to do this. Please... (2 Replies)
Discussion started by: tipsy
2 Replies

10. Shell Programming and Scripting

how to find today's files & send to another server?

Hi All, My script has to find todays modified( less than 24 hrs) files & send it another server using SCP. what I wrote is find . -type f -mtime -1 | xargs ls -ltr ## to find today's files, but its giving my sh_history file also, I don't require this file at all. scp... (4 Replies)
Discussion started by: zinu
4 Replies
Login or Register to Ask a Question