Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to run a perl script on a set of files and I guess I am doing something wrong.
On one file the command is:
process.pl $infile.in $outfile.out
that works just fine for one file
When I try to run it on a set of files using this command:
for i in $(ls -1 *.sgm); do cat $i | utf82buck_linux.pl $(basename $i) $(basename $i).out; done
the output files are empty, no processing is done.
I changed your script slightly to show you a debugging technique for problems like this. Essentially it is using echo to print what would have happened. This allows you to see the problem(s).
You may need to change this because it wasn't clear to me exactly what you wanted:
Code:
#!/bin/sh
# @(#) s1 Demonstrate a debugging technique.
# for i in $(ls -1 *.sgm); do cat $i | utf82buck_linux.pl
# $(basename $i) $(basename $i).out; done
echo
for i in $(ls -1 *)
do
echo utf82buck_linux.pl $(basename $i) $(basename $i).out
done
So it looks like the filenames (mine) are getting to the loop. I omitted the cat, because it seemed unlikely that you needed that.
What do you see for the commands? Did you really want $infile.in?, does the perl script really process two arguments, one for input and one for output? and so on ... cheers, makyo
I tried to omit cat by running:
for i in $(ls *.in); do process.pl $(basename $i) $(basename $i).out; done
but I still get the output files (*.out) empty
All I want to do is run :
process.pl $infile.in $outfile.out
on a set of files with the extention *.in
Thanks for the debugging commands, i was not sure how to use them.
I tried to explain what I want to do with the command, anything that looks incorrect in it.
thanks again
Rita
The set of shell commands you have is very close. Here are the changes I would suggest.
Code:
for i in $(ls *.in);do process.pl $i $i.out;done
You should be executing these in the directory where your .in files are located. There is no need to use the basename command since when you execute ls *.in in the current directory all you get is the filenames. Is process.pl in a directory that is in your $PATH?
With these commands an input file with the name stuff.in will have an output filename of stuff.in.out. If you want the filename to be stuff.out substitute ${i%.*}.out for $i.out.
If you are still not getting output files after this, maybe we should be looking at process.pl.
Hi Bill,
Thanks for your reply. The script you sent me might be working except that I get two error in processing a couple of file. THe error doesn't give me the name of the input file that gives the problem.
Is there a way to print the name of the input files being processed so I know which one causes the problem.
Thanks again
Rita
Do any of your input files have spaces in their names? The script could interpret these incorrectly. Try putting double quotes around "$i" and "$i.out".
If you want to see what files are being processed, replace process.pl with the echo command as Makyo suggested. This will give you a listing of what files are being fed into process.pl. Perhaps from there you can determine the input files causing the problem.
Bill, the command you sent me actually works. for the ls *.i, I was giving the path to a different directory. The output files were created in that directory, not the current directory.
I also figure what files give the errors!!
Thanks for your help.
Rita
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.