-   Linux - Software (
-   -   Trouble with making a bash script to read in different files and rename output files. (

rystke 05-07-2009 07:46 AM

Trouble with making a bash script to read in different files and rename output files.

Obviously im new here, but long time Ubuntu and Fedora user. Until now i haven't had to dabble with bash scripts.

So, my problem is this.... I have a program that reads in data files. These are named datafile01_R, datafile01_G, datafile01_B, they then increment, so datafile02_R etc i have about 600 of these. the program reads in 3 data sets at a time from each run, so files_01 r, g, and b.

The program then does its magic, and outputs about 40 different files, depending on the file, they gone to folders named R, G, B, psa, or tracking.

The program itself has configuration files to say where the files should gone when analyzed, there is also the config files that reads in the data sets.

at the moment i have to run one set of data, then go in and manually change the input file location, and run again. But, doing this, even though a different data set, the new set overwrites the old set in one of the output folders. So i need a way to increment the output filenames after they are written and before the program is run again with the new data set.

I have had a look at doing this but keep getting very confused, im hoping one of the guru's here may be able to help me!

Many thanks

blacky_5251 05-07-2009 08:00 AM

You can ensure unique file names when you move the files into the archive area by doing something like this:-

SUFFIX=$(date +%c.%N)
mv src_file dest_file.$SUFFIX

The value of $SUFFIX is set from the output of the date command, which has been told to return the date in seconds since the UNIX epoch (1970), and the current nanoseconds. While not guaranteed, I'm fairly positive that this will provide unique filename in the archive directory.

All times are GMT -5. The time now is 05:29 AM.