I have a file called "list1" - its got about 80 rows - each row is
alpha numeric name w/ ".txt" extension - each name refers to a file in
the dir.
The script reads the list - for each name in the list, it will perform
an operation (an executable of a "C-program" and writes to same name
with a different extension, say ".mp3".
Thanks
Nice. What have you written so far? And why didn't you opted for bash?
Rui Maciel
I changed it to bash but the code didn't work
THis is what I really need:
In a summary:
1) say about 80 files (but varies) in a dir with filenameX.txt
extension.
2) CONV1 runs one at a time and gives output w/ a fixed name, CONV.out
3) CONV2 takes CONV.out as well as the final output file (which is
filenameX.mp3). Ideally it puts them in a specified directly.
I really appreciate your help - I want something that works - I
started off with t shell - I am open to change to bash or perl. I
prefer a simpler looking program
Ok.
What is your question (if you got any) or the point of your posting?
jue
I need help in writing please
Also, if I use "print" within perl to the dump a executable command to
the monitor, will the process be executed and the perl will wait
before it throws the next one to screen?
$ cat list1 | while read filename; doAm I missing something?
> CONV1 $filename
> CONV2 CONV.out
> done
> Based on your sketchy requirements I'd say (in bash):
>
> $ cat list1 | while read filename; do
> > CONV1 $filename
> > CONV2 CONV.out
> > done
>
> Am I missing something?
Yes, he was trying to get someone to do his work. He obviously never even
gave it a try, not in perl and obviously not in bash. After all, it's one
of the recurring examples in each and every bash tutorial on the web.
Rui Maciel
> On Apr 5, 3:24 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
...
>> What is your question (if you got any) or the point of your
>> posting?
...
>
> I need help in writing please
>
First, try to help yourself.
If you want the script written for you, I am sure there will be a
few people who'd do it for $500. If you want tech support to go with
that, maybe $750. If you would like me to write it, the rate goes up
to $2500.
If you are willing to pay for the job, then post an announcement at
http://jobs.perl.org/
Otherwise, try to solve your problem first on your own (make sure to
consult the various resources available to you) and then post
concrete questions here.
Sinan
--
A. Sinan Unur <1u...@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
Ok, what do you have so far? Show us your current code, explain what it
is supposed to do (you got that part already), what it is actually
doing, or where you are stuck. I am sure someone will be happy to show
you how to get unstuck.
>Also, if I use "print" within perl to the dump a executable command to
>the monitor,
This sentence doesn't compute. I have absolutely no idea what you are
talking about.
>will the process be executed and the perl will wait
>before it throws the next one to screen?
print() has nothing to do with process control. Where did you get that
idea?
jue
First, try to help yourself.
If you want the script written for you, I am sure there will be a few people who'd do it for $500. If you want tech support to go with that, maybe $750. If you would like me to write it, the rate goes up
to $2500.
I need help in writing please
Also, if I use "print" within perl to the dump a executable command to the monitor, will the process be executed and the perl will wait before it throws the next one to screen?
my $cmd = "CONV1 $filename";Change this to:
my @output = `$cmd`;
my $status = $?;
die "Unable to execute $cmd" if $status != 0;
$cmd = "CONV2 $filename2";
@output = `$cmd`;
die "Unable to execute $cmd" if $status != 0;
my $cmd = "CONV1 $filename";So here I'm just printing out what $cmd contains. Note I commented out the actual execution of the commands on the assumption that you didn't want to actually execute them unless you saw that they looked OK. Actually I would do this in Perl's debugger instead stopping at the statement that was about to execute the $cmd and display it's contents and only stepping forward if it were correct.
print "About to execute \"$cmd\"\n";
#my @output = `$cmd`;
#my $status = $?;
#die "Unable to execute $cmd" if $status != 0;
print "About to execute \"$cmd\"\n";
#$cmd = "CONV2 $filename2";
#@output = `$cmd`;
#die "Unable to execute $cmd" if $status != 0;
Rui Macial has already told you: "Do not let others do your homework!"
Try some coding first.
Moreover, many neebies have asked the same question, you will find
helpful replies.
This works at least in ksh/bash: (no shell builtins for var-substitution)
while read file
do
f_short=$(echo $file | cut -d . -f 1) # strip the .txt suffix
C_PROGRAM $file > "${f_short}.mp3"
done < list1
--jk
> Subject: Newbie wants a simple script in perl
Newbie should begin writing a simple script in Perl.
Newbie should post the broken code here when you get stuck.
Then we will help newbie fix the broken code.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
> Also, if I use "print" within perl to the dump a executable command to
> the monitor, will the process be executed and the perl will wait
> before it throws the next one to screen?
1) As written: It simply does not happen that way.
2) I use something like that all the time, by piping the output
from a perl script into 'sh' or 'bash'.
perl generate_commands.pl input.txt | sh
The logic for generate_commands.pl is quite simple.
1) Use <> to read list of names, one line at a time.
2) Parse the input line to get the name of an input data file.
3) Come up with the name of an output file based on that.
4) Execute an external command, giving it the names of the
input data file and output file.
5) Execute a second external command.
6) Loop back to step 1 until end of list.
There are several ways to perform step 4:
my $results = `$command1 $in_file $out_file`;
or
my $error_code = system "$command1 $in_file $out_file";
warn "Something went wrong: $? ($!)" unless $error_code == 0;
or
print PIPE "$command1 $in_file $out_file\n";
The other steps are so trivial that you won't have any problem
finding them in any Perl tutorial.
That should be enough for you to write the script yourself. Good luck.
-Joe