Running a script over a series of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a script over a series of files
# 1  
Old 03-27-2013
Running a script over a series of files

Hi,

I want to run a script over a series of files with the names :

Sample_1.sorted.bam
Sample_2.sorted.bam
Sample_3.sorted.bam

How can I specify it in my script. Thanks a lot in advance.
# 2  
Old 03-27-2013
What have you tried so far?
# 3  
Old 03-27-2013
I think you're looking for this kind of code:
Code:
for file in *.bam; do
  echo $file
  # do something
  # do something else
done

Or more specific file spec:
Code:
for file in Sample_*.sorted.bam; do
  echo $file
  # do something
  # do something else
done

Hope this helps.
# 4  
Old 03-27-2013
By the way if you want to pass these file names as arguments to your script, use shell ENV variable $@
Code:
./your_script Sample_1.sorted.bam Sample_2.sorted.bam Sample_3.sorted.bam

"$@" is replaced with all command line argument.

Also note that white-space within an argument is preserved when enclosed in double quotes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with running a script on files located in subdirectories

Hello everyone, I'm am a newbie to coding so I am reaching out in hopes that I can get some help from this forum. I am trying to run the script below from a single directory, however the directory has many subfolders. In each of those subfolders is a file, uniquely named to that specific... (3 Replies)
Discussion started by: azurite
3 Replies

2. UNIX for Dummies Questions & Answers

Create Sym Links for a series of files

Hello, I would like to create symbolic links for a series of files in my cwd (after confirming that the links don't already exist). The above files all have a similar prefix, but different extensions. I created a shell script like shown below and I get an error message "No such file or... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

3. Shell Programming and Scripting

Running q-shell commands( on IBM-i Series) from cygwin terminal (on windows)

I have cygwin installed on windows server and when I do echo $SHELL the output is /bin/bash I have created a ssh tunnel from this windows server through cygwin to ibm -i series which is running Q-shell. I am trying to invoke a utility wsadmin (used for scripting) on ibm-i from the... (12 Replies)
Discussion started by: gaurav99
12 Replies

4. UNIX for Dummies Questions & Answers

How to zip up a series of log files in one shot?

Hi, I'm trying to zip up the first half year's application logs into one zip file. The logs are in the format of log.2011-01-01 to log.2011-06-30. I tried to use this command at ksh: zip logs.jan-jun2011.zip *2011-01* *2011-02* *2011-03* *2011-04* *2011-05* *2011-06* It works. However, I... (4 Replies)
Discussion started by: hyang
4 Replies

5. Shell Programming and Scripting

awk - extracting data from a series of files

Hi, I am trying to extract data from multiple output files. I am able to extract the data from a single output file by using the following awk commands: awk '/ test-file*/{print;m=0}' out1.log > out1a.txt awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4 ;m=0}' out1.log >... (12 Replies)
Discussion started by: p_sun
12 Replies

6. Shell Programming and Scripting

Running batches of files at a time from a script

Hi I have a script that performs a process on a file. I want to know how to include a function to run a batch of files? Here is my script #!/bin/bash #---------------------------------------------------------------------------------------------------------------------- #This... (2 Replies)
Discussion started by: ladyAnne
2 Replies

7. Shell Programming and Scripting

Running a script with all files in a folder

Hi I have many files in a folder (like 200) and I want to run a Perl script through all of them. One way would be to do it one by one (which will take forever). But I am sure there is a faster way of doing it. So inside the folder i have files named in no particular way eg. YUI456... (3 Replies)
Discussion started by: phil_heath
3 Replies

8. UNIX for Dummies Questions & Answers

For Loop to execute a command on a series of files

Hello, I have a set of input data that I split into batches using the following command: split -l 4000000 MyInput.in Split_a Once I get the split files, I run a certain command on the split files that spews an output. So far I have been doing it without a for loop. How can I translate the... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

9. Shell Programming and Scripting

running a looping script for all files in directory

I have three different linux command scripts that I run for 20+ files in one directory. it goes like this FIRST SCRIPT: grep 'something' -w file > newfile1 . . . grep 'something -w file > newfile20 then I take all these 'newfileN' and run this: awk 'BEGIN {... (20 Replies)
Discussion started by: labrazil
20 Replies

10. UNIX for Dummies Questions & Answers

How do I organize a series of files in date order?

I'd like to ls a group of files in date order but I'm not sure what the commands would be. Can anyone help with this? (1 Reply)
Discussion started by: hedgehog001
1 Replies
Login or Register to Ask a Question