LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-26-2006, 01:07 PM   #1
gamor
Member
 
Registered: Jul 2004
Posts: 77

Rep: Reputation: 15
running a script on a set of files


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.

Please let me know how to fix this command

thanks
 
Old 12-26-2006, 01:25 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,889

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
Quote:
ls -1 *.sgm
Go to any directory and do 'ls -l'. What do you see?

The filename is the last field in the output. If you want your script to work with 'ls -l' you will have to grep the filename from the output.

Or, make it easy on yourself and drop the '-l' from the command so that ls only shows the filename.
 
Old 12-26-2006, 01:38 PM   #3
gamor
Member
 
Registered: Jul 2004
Posts: 77

Original Poster
Rep: Reputation: 15
I tried that but the output files are still empty
Any other suggestions?
thanks
Rita
 
Old 12-26-2006, 01:54 PM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 729

Rep: Reputation: 75
Hi.

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
Which results in:
Code:
% ./s1

utf82buck_linux.pl Readme.txt Readme.txt.out
utf82buck_linux.pl a.sgm a.sgm.out
utf82buck_linux.pl b.sgm b.sgm.out
utf82buck_linux.pl s1 s1
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
 
Old 12-26-2006, 02:30 PM   #5
gamor
Member
 
Registered: Jul 2004
Posts: 77

Original Poster
Rep: Reputation: 15
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
 
Old 12-26-2006, 02:41 PM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 729

Rep: Reputation: 75
Hi, Rita.

Where do the files $infile.in come from? You do not have the ".in" extension in your script ... cheers, makyo
 
Old 12-26-2006, 03:02 PM   #7
gamor
Member
 
Registered: Jul 2004
Posts: 77

Original Poster
Rep: Reputation: 15
I thought the variable $i would have the filename with the extention .in
Am I wrong?
Rita
 
Old 12-26-2006, 06:02 PM   #8
gamor
Member
 
Registered: Jul 2004
Posts: 77

Original Poster
Rep: Reputation: 15
I tried to add the extention by using;
for i in $(ls *.in); do process.pl $(basename $i .in) $(basename $i).out; done

The output files are still empty.
I need some help here. I cannot see what s wrong with the command

thanks
 
Old 12-26-2006, 06:53 PM   #9
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 23, 24, RHL 5.2
Posts: 560

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

Bill

Last edited by wmakowski; 12-26-2006 at 07:02 PM.
 
Old 12-27-2006, 08:34 AM   #10
gamor
Member
 
Registered: Jul 2004
Posts: 77

Original Poster
Rep: Reputation: 15
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
 
Old 12-27-2006, 11:03 AM   #11
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 23, 24, RHL 5.2
Posts: 560

Rep: Reputation: 56
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
 
Old 12-27-2006, 12:34 PM   #12
gamor
Member
 
Registered: Jul 2004
Posts: 77

Original Poster
Rep: Reputation: 15
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
 
  


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
Set ETHO in RUNNING mode ziobudda Linux - Networking 2 07-12-2006 07:19 AM
Script to set userpassword BrianFFM Programming 3 02-24-2004 05:19 AM
Running FTP inside Shell Script truncates files jbhanc0125 Red Hat 3 01-16-2004 11:37 AM
how to set workspace when running an app evian Linux - General 1 08-17-2003 04:18 PM
Running bash script files in C++ (Kylix) Acherion Programming 4 07-25-2003 11:35 PM


All times are GMT -5. The time now is 02:08 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration