Automatic file input to code

i have got many files like this in my folder temp(say)
imp_02042008.txt for date 02-04-2008
imp_03092009.txt for date 03-09-2009
imp_25112009.txt for date 25-11-2009
...................
........
in some folder.
and one of my shell code uses one of the above files based on date.
for example for todays date it should pick the file imp_25112009.txt
for tomorrows date it should pick the file like imp_26112009.txt
My code is like below one:
print substr($1,4,3),"",substr($2,22,8) inputfile.txt>outputfile.txt

This code should run on day to day basis.
What i want is a code to pick up the file (eg..imp_26112009.txt) automatically from folder temp based on day.. i.e, for a given day particular file should be taken as input in my code...
pls help me in this regard..

---------- Post updated at 07:14 AM ---------- Previous update was at 07:02 AM ----------

pls any coders do look into matter... m novice to shell scripting...

in bash, it is one of the simplest way to form your file name ...

todaydate=`date +%d%m%Y`
echo $todaydate
file=imp_$todaydate
echo $file

output:

25112009
imp_25112009

if you want to run it daily automatically, call it normally from cron.

what i want is to pick up file from the temp directory if its todays file.that file will act as input to my code... I already have files in the given form.. i need some code that will search the file(of current date.. i.e for today i need to pick file imp_25112009) from temp directory and place it as input to my code...

wat m searching is code which contains sed or grep or awk...etc something like that...

sorry for disturbance... n thank you for ur help... :slight_smile:

Do you mean like this: -

nawk ' 1 ' imp_$(date +%d%m%Y) > outputfile.txt

thank you for your help. but my requirement has slightly changed..i have got directory home/ext/eca/pool that contains
below kind of files...

imp_05172_02042008_124956_02042008_123.txt

imp_01342_02042008_124956_02042008_128.txt

imp_02229_25112009_124956_25112009_222.txt

imp_02347_26112009_124956_26112009_332.txt
.....
....

what i want is that my code should pick the file corresponding to current date i.e for today it should pick the file imp_02347_26112009_124956_26112009_332.txt
here the numbers before&after 26112009 doesnt make any difference to me..

i tried following code:

cat </dev/null >inputtomycode.txt;

awk '$0 ~ /^imp_$(date +%d%m%Y) {print $0}' /home/ext/eca/pool> inputtomycode.txt

but its not working properly...some loopholes in code..pls help to patch up the code...

by the way is there any way how to make my code run regularly at specific time..(say my code file name is reg.txt) ..?

Is cron will suffice my need....

---------- Post updated 11-27-09 at 01:46 AM ---------- Previous update was 11-26-09 at 07:57 AM ----------

anybody pls look into above post

You might want to try to explain what you mean by things like "pick up the file". Instead use terminology that most people generally understand for instance:

"I want to read the file1 that corresponds to todays date in folder tmp, and input that file into file2.... file2 is located in a different subdirectory, and I need this to run automated. eg. using cron."

rather than "pick up" use terminology like "read or write" "input or output"

ok... you have you have described wat my requirement is... thanQ

unfortunately, I don't know unix programs enough to help I was simply trying to help you get a result, otherwise people generally read through a topic, try to help but get frustrated because they can't understand what the OP is trying to accomplish or what their needs are, and so they unsubscribe and don't bother replying or continuing to help.

However you have been given some guidelines already, you don't need to worry about the automate processes just yet, figure it out until the script works then you can read up on how to use cron: "man cron"

did you play with steady's example?

nawk ' 1 ' imp_$(date +%d%m%Y) > outputfile.txt
ls | xargs -n1 | nawk '/imp_[0-9]*_'$(date +%d%m%Y)'_[0-9]*_'$(date +%d%m%Y)'_[0-9]*.txt/' /home/ext/eca/pool> inputtomycode.txt

thanQ guys..finally its working..