Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-07-2009, 08:46 AM   #1
LQ Newbie
Registered: May 2009
Posts: 1

Rep: Reputation: 0
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
Old 05-07-2009, 09:00 AM   #2
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script? how to rename files in random way? lefty.crupps Linux - Software 16 11-03-2015 03:07 PM
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 04:50 AM
bash script to rename files removing one character Byenary Linux - Newbie 2 04-08-2008 11:12 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-23-2008 12:25 AM
Bash script to traverse directory tree and rename files intramaweb Programming 3 10-08-2006 01:51 PM

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration