Automatic file input to code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatic file input to code
# 1  
Old 11-25-2009
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...
# 2  
Old 11-25-2009
in bash, it is one of the simplest way to form your file name ...

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

output:
Code:
25112009
imp_25112009


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

Last edited by thegeek; 11-25-2009 at 09:26 AM.. Reason: placing output also
# 3  
Old 11-25-2009
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... Smilie
# 4  
Old 11-25-2009
Do you mean like this: -

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

# 5  
Old 11-27-2009
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
# 6  
Old 11-27-2009
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"
# 7  
Old 11-27-2009
ok... you have you have described wat my requirement is... thanQ
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with the code to do automatic task in plink

Hi, I am newbie tothis forum and also to unix. i wa shownt help in giving me a acceptable code so that i could add it as batch to be included in the task scheduler. i use plink and putty to login to my router. With this i get to the $, linux prompt there i have to issue a command show... (5 Replies)
Discussion started by: jraju
5 Replies

2. Shell Programming and Scripting

Automatic input "yes" in a shell script

Hi All, I need a favour. I have a file called "redhat_servers.txt" containing some server names line by line. When I try to ssh to each server, and I have already done with ssh key-gen stuff. Now, for first time if I do ssh .. I need to type yes I have more than 400 servers...it will take... (4 Replies)
Discussion started by: kumar85shiv
4 Replies

3. UNIX for Dummies Questions & Answers

[Solved] How to refer to input file in code?

This may be a dumb question, but googling is not giving me an answer. I'm trying to figure out how to refer to an input file in my code. Lets say i run a script in bash: "sh shellscript.sh inputfile" (Inputfile will be variable...whatever file i run the script on) I wanted to make... (5 Replies)
Discussion started by: legato22
5 Replies

4. Shell Programming and Scripting

[KSH] Creating automatic variable from read input

Hello there, I am posting to seek help with a KSH script, I am making a simple calculation program where the user can enter as many numbers as they like, I am getting their input using the read command, however I am not sure how to repeat doing this and storing the input in to new variables... (7 Replies)
Discussion started by: pandapowerbox
7 Replies

5. Shell Programming and Scripting

Automatic Input to a command

Hi, I have an issue where i run an command in a shell script. command >/dev/null ret=$? echo ret If the command returns an error i'm redirecting it to /dev/null. The prob is if an error comes it expects the user to press return to continue. And hence the return is not echoed. and the end... (4 Replies)
Discussion started by: subhrap.das
4 Replies

6. Shell Programming and Scripting

Giving automatic multiple Input to a tool from shell script

Hi, Please help me,its urgent. I have a tool that i want to run from a shell script. When we run the tool it will ask the user choice to add or delete. When user enter the choice it will then ask how many units he want to delete or add and will add or delete accordingly. Now I want to... (1 Reply)
Discussion started by: saket18@ymail.c
1 Replies

7. UNIX for Dummies Questions & Answers

12. If an ‘88’ Record with BAI Code ‘902’ was found on input file and not written to Output file, re

This is my input file like this 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+00000000354,,/ 49,+00000000000416920,00002/ 03,5313236,,015,+00231036992,,,045,+00231036992,,,901,+00000048428,,/ 88,100,+0000000000000,0000000,,400,+0000000000000,0000000,/ 88,902,+0000000079077,,/... (0 Replies)
Discussion started by: sgoud
0 Replies

8. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

9. Shell Programming and Scripting

[code] Automatic File Input

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.... (0 Replies)
Discussion started by: Maruti
0 Replies

10. UNIX for Advanced & Expert Users

Automatic input to commands

Hi, In a shell script i am running a command which is asking for input. How can i give that automatically. I have done this before but for the time being can't recall. Was something like <| Thanks (6 Replies)
Discussion started by: vibhor_agarwali
6 Replies
Login or Register to Ask a Question