LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-07-2009, 07:46 AM   #1
rystke
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.


Hey,

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, 08:00 AM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 55
You can ensure unique file names when you move the files into the archive area by doing something like this:-
Code:
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.
 
  


Reply


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 15 06-08-2014 03:47 PM
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
bash script to rename files removing one character Byenary Linux - Newbie 2 04-08-2008 10:12 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-22-2008 11:25 PM
Bash script to traverse directory tree and rename files intramaweb Programming 3 10-08-2006 12:51 PM


All times are GMT -5. The time now is 03:23 AM.

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