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
# 8  
Old 04-24-2009
If you don't need to go down in the directory three and you don't want the relative path displayed, you can use Perl:

Code:
perl -le'print join ",",grep 1 > -M, <*>'

The above command will not display hidden files (add .* to the glob if you want to include them).
# 9  
Old 04-24-2009
The reason you get the . is due to the find command.

The solution is not ideal as you will be getting the first . and an end ,

If you do the find command on its own you will see you get

.
./WS2003-WindowsMedia-BD.doc
./avcodec_sample.cpp

All the tr is doing is changing newline character \n to be ,

You may want to do something like

Code:
filelist=$(find . -type f -mtime 0 | tr '\n' ',')

If you are in ksh you could then strip off the last , of filelist with

Code:
filelist=${filelist%?}    #actually strips of last character

# 10  
Old 04-24-2009
Thanks a lot for the timely help....
# 11  
Old 04-27-2009
Hi all,

I am facing another issue with this find.....

Here is my program



#!/bin/sh
# Environmental set up
envSet="true";

# Initialize error code
error_code="false";

if [ "$envSet" = "$2" ]
then
# Set batch environment
. $1/jobs/setBatchEnv.sh $1
fi

echo "file name ---------"$filename
echo "BATCH_HOME ---------"$BATCH_HOME
echo "3 ---------"$3

#Frame the output file name
if [ "$filename" != "" ]
then
echo "Inside IF"
#if ZipReports.sh executed, then the filename of the zip will be taken from that
outfilename = $filename;
else
echo "Inside ELSE"
#if ZipReports.sh not executed, then the filename will be the list of files that are last modified today
cd $BATCH_HOME/data/output/$3
pwd
outfilename=$(find . -type f -mtime 0 | tr '\n' ',');
fi

echo "outifle-------"$outfilename

# Call the EmailReportsBatch.java program
$JAVA_HOME/java -Xmx1024m -Djava.awt.headless=true \
-DPROPERTIES_PATH=$BATCH_HOME/properties \
-DREPORT_TYPE=$3 \
-DOUTPUT_PATH=$BATCH_HOME/data/output/$3/ \
-DOUTPUT_FILE=$outfilename \
batch.EmailReportsBatch > $LOG_DIR/EmailReportsBatch.log

# Check if java command fails
if test ! $? -eq 0
then
error_code="true";
fi




When i execute this pgm i am getting the outfilename value correctly. But when it is invoked from main shell this outfilename is giving me one value less than what it is supposed to give. That is if 3 files are modified today, it is giving only 2 file names. Any suggestion why this is happening?Smilie But when BATCH_HOME, $3 values are echoed they show the same results...


Thanks,
Ananthi.U
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