LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2005, 03:26 AM   #1
rohr
Member
 
Registered: Jan 2005
Distribution: debian
Posts: 44

Rep: Reputation: 15
Question different names for output files


Hi, i need help with the following:

i have two bash script, the first one produces as output ASCII data files and the second one takes these and produces ".eps" output graphs calling gnuplot to manage this.

Up to now, each time a call the first script and then the second i get, say, some graphical output files like fileA.eps, fileB.eps fileC.eps.

But if i make this procedure again, calling the two bash scripts over there, it overwrites fileA.eps, fileB.eps fileC.eps and i lost all ".eps's" i got the first time.

So i need some way such that if i call those bash scripts, say, four times, it gives me as output something like:
Code:
fileA1.eps fileB1.eps fileC1.eps
fileA2.eps fileB2.eps fileC2.eps
fileA3.eps fileB3.eps fileC3.eps
fileA4.eps fileB4.eps fileC4.eps
where each line correspond to a call for those two scripts.

Thank you in advance for any response.
Bye.
 
Old 03-23-2005, 09:40 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
Code:
#!/bin/bash

flist=`ls fileA*.eps 2> /dev/null`
fnum=`echo $flist | sed -e 's/.*\( \)*\(fileA\)\([0-9]\+\)\(\.eps\)/\3/g'`
#echo $fnum
if [ -z $fnum ]; then
  fnum=1
else
  fnum=`expr $fnum + 1`
fi
echo "creating fileA$fnum.eps"
touch fileA$fnum.eps
echo "creating fileB$fnum.eps"
touch fileB$fnum.eps
echo "creating fileC$fnum.eps"
touch fileC$fnum.eps
modify this as per your needs.
 
Old 03-23-2005, 09:44 AM   #3
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
One way to handle this would be to initialize a counter variable at the beginning of the script. Then, run a while loop which tests for the existence of fileA$counter.eps, and increments the counter if it exists. Once you find an A file that doesn't exist, you can pretty safely assume that B & C don't exist either..

Code:
counter=1

while [ -e "./fileA${counter}.eps" ]; do
  counter=$(($counter+1))
done

# From now on, refer to files as fileA${counter}.eps, etc.
#
That should solve the duplicate issue.
 
  


Reply



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
files that have spaces in their names hesher Linux - Software 5 01-14-2005 01:43 PM
bash:output file names from shell script to vi sickboy Linux - Newbie 6 10-14-2004 03:40 AM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM
konqueror help files names RealGomer Linux - Software 1 01-18-2004 06:44 PM
Files with spaces in their names downinthemine Linux - General 3 12-12-2003 01:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration