0

I have a script that I need to run on every file in a folder. The script creates a new file with the same name as the original file in a new folder.

So the folder contains files with names like:

SLX-8691.ART12.seq
SLX-8690.ART12.seq
SLX-8692.ART12.seq
SLX-8693.ART12.seq

The script I want to run on every file isexample is as follows:

$ ./unique_seq_counts.rb ./qualitymask/SLX-8691.ART12.seq > ./uniquecounts/SLX-8691.ART12.counts.txt

So that SLX-8691.ART12.seq is replaced by each file name.

Is there a way of looping through a replacing each filename automatically?

Thanks

1
  • Yes, you use variables. You can use reference them when renaming as if they were strings. They'll be expanded. There are multiple examples of similar stuff here on SO and on superuser. Commented Aug 2, 2014 at 12:21

1 Answer 1

1

Using a loop:

for F in ./qualitymask/*.seq; do
   T=${F##*/}  ## Removes directory part. Same as $(basename "$F")
   T=${T%.seq}.counts.txt  ## Removes .seq and adds .counts.txt
   ./unique_seq_counts.rb "$F" > "./uniquecounts/$T"
done

See: Parameter Expansion and Filename Expansion.

Sign up to request clarification or add additional context in comments.

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.