1

I have thousands of two set of files one with name.ext and another files name ending with name.ext.in, so for every name.ext there is a name.ext.in and now i have to pass this as argument to a script such as customise.pl name.ext name.ext.in. I am doing like

#!/bin/bash 

FILE1=$.ext
FILE2=$.ext.in

customise.pl $FILE1 $FILE2

but no success. Any idea?

1
  • You surely have to loop through the list of files, in order to run your customise.pl for each pair. Commented Feb 2, 2014 at 19:56

5 Answers 5

4
for i in *.ext; do 
    customise.pl "$i" "$i.in"
done
Sign up to request clarification or add additional context in comments.

1 Comment

Just in case there is whitespace in any of the filenames, it is probably a better idea to do customise.pl "$i" "$i.in".
2

Judging from the comments to the other answers, you probably want something like this:

for file in *.ext; do
    customise.pl "$file" "${file%.*}.new.psl"
done

The ${file%.*} syntax substitutes only the part of $file up until its last dot. You can check the manpages for Bash or Dash for more information on it if you need.

Comments

0

If you want to run customise.pl for each pair of files, you can do it like this in a bash script:

#!/bin/bash

for i in `ls *.ext`
do
  customise.pl $i $i.in
done

3 Comments

for i in $(ls *.ext) has the problem that it doesn't deal with whitespace and quoting properly. for i in *.ext works better.
if it is like name.ext and the second file is like name.XYZ.in where XYZ is a common in the header of the second file.
Hi thanks, but the problem is that only name is similar I have thousands of two set of files one with name.ext and another files for the same name ending with name.new.psl, so for every name.ext there is a name.new.psl and now i have to pass this as argument to a script such as customise.pl name.ext name.new.psl. Any idea for loop in bash. The first name is common for the each name.ext and name.new.psl like perl customise.pl name.ext name.new.psl
0

I guess the simplest form is

    for f in "*.ext"
    do                 
         customise.pl  $f.ext $f.ext.in      
    done

OUTPUT:

1 Comment

Hi thanks. I have thousands of two set of files one with name.ext and another files for the same name ending with name.new.psl, so for every name.ext there is a name.new.psl and now i have to pass this as argument to a script such as customise.pl name.ext name.new.psl. Any idea for loop in bash. The first name is common for the each name.ext and name.new.psl like perl customise.pl name.ext name.new.psl
0

another way.

ls *.ext |xargs -i customise.pl {} {}.in

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.