Looping through files in pairs

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping through files in pairs
# 1  
Old 11-06-2013
Looping through files in pairs

Hi all,

Please guide. It has to do with parsing the input file names.

I have a fairly large number of files, I want to do some operations on them in a pairwise fashion (every file has a pair).

The names are in the following pattern, with the pairs of files named with _1 and _2 , the extension .xy is the same for all files. Also I want to save the outputs in the corresponding somenameN directory. So the output from
somename1_1.xy and somename1_2.xy are stored in the somename1 directory created on the fly.


So I want to do something like

for file in *
   mkdir somenameN  
   do_something_with  file_1.xy  file_2.xy > ./somenameN/somenameN_out

# 2  
Old 11-06-2013
How about:
for file in *1.xy
  if [ -f "$file" ]; then
    echo "$file ${file%1.xy}2.xy"

Last edited by Scrutinizer; 11-06-2013 at 01:48 PM..
# 3  
Old 11-06-2013
I think the key here is to only match one of the pair, for example...
for file in somename*_1.xy ; do echo ${file} ; done


for file in somename*_1.xy
 echo ${file}
...insert whatever magic....

# 4  
Old 11-06-2013
Try sth like
for file in $(ls | sed 's/_[12].xy//' file | uniq)
  do mkdir "$file"N
     do_something_with  "$file"_1.xy  "$file"_2.xy > ./"$file"N/"$file"N_out

# 5  
Old 11-06-2013
while read filename1 && read filename2
done < inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Error in looping through files

Hi, I've got a folder with several files I'd like to manipulate. The file names are all ending in .txt and I'd like to loop through their names for manipulation. This is the script I've got so far: for i in 'ls *.gtc.txt|cut -d "." -f1'; do echo${i}; done It should be easy enough, but... (2 Replies)
Discussion started by: zajtat
2 Replies

2. UNIX for Dummies Questions & Answers

Concatenate files by pairs

Hi, I would like to batch concatenate files by pairs. I have quite a few of them so I would not like to do that pair by pair separately. the names of the file is of the type: file1.fastq newfile1_new.fastq file2.fastq newfile2_new.fastq and so on... I would like to concatenate file1... (2 Replies)
Discussion started by: jawad
2 Replies

3. Shell Programming and Scripting

Looping through Files

Hi all , I am new on this forum . I have to face a particoular implementation issue and I need some help . Requirement : I need to read a particoular file (an xml file) and after reading it I need to call an Oracle Stored Procedure passing the content of the file as paramenter , in order... (3 Replies)
Discussion started by: Kolas79
3 Replies

4. Shell Programming and Scripting

Looping through pairs of files with awk

Hi all, please help me construct the command. i want to loop through all files named bam* and bed*. My awk works for a particular pair but there are too many pairs to do manually. I have generated multiple files in a folder in a given pattern. The files are named like bam_fixed1.bam... (2 Replies)
Discussion started by: newbie83
2 Replies

5. Shell Programming and Scripting

Conditional Looping In Files

I have a req. where i need to read data from multiple files and take counts of row which satisfy the condition. e.g.: FILE1: Col1 Col2 Col3 12 ab cd 15 de fg 25 gh tm FILE2: Col1 Col2 Col3 21 ab1 cd1 13 de1 fg1 25 gh1 tm1 --- --- FILE-N... i need to find the count of rows... (6 Replies)
Discussion started by: kunal007
6 Replies

6. UNIX Desktop Questions & Answers

trying to cat multiple pairs of files

I have a number of files in a directory named like this: fooP1, fooN1, fooP2, fooN2 ... fooP(i), fooN(i). I'd like to know how to combine each P and N pair into a single file, foo(i) TIA John Balwit (1 Reply)
Discussion started by: balwit
1 Replies

7. Shell Programming and Scripting

looping through files

I am writing a ksh which has to load 7 files(.dat files) from input directory into oracle tables using sql loader. The process has to take each file at a time and once if it is loaded succesfully using sql loader into oracle tables then the process has to pick next file and load it into oracle... (2 Replies)
Discussion started by: vpv0002
2 Replies

8. Shell Programming and Scripting

Looping through files...

I posted this in the Solaris forum, but I don't think it's platform specific, so I'm posting it here. Here is the situation. We are a company that has been using a professional publishing system, the software is called "ProType". It runs on Solaris 2.4, however it is no longer supported and we... (6 Replies)
Discussion started by: Fred Goldman
6 Replies

9. Shell Programming and Scripting

Help looping through files, please...

Okay... I've solved one problem. Here's the next. I'm writing a script file that needs to go through a directory and list all files in that directory. I'm using TCL/TK. I figured out how to go through the directory and how to loop through it, but I ran into a little problem. ... (2 Replies)
Discussion started by: kapolani
2 Replies

10. Shell Programming and Scripting

looping files

Hi, I have a file a.lst which lists all files. as a.dat b.dat c.dat I want to process these files mentioned in the list file in a loop. Say I want to display only the first line of all the files a.dat , b.dat, c.dat. How can I go about it? Please help. (5 Replies)
Discussion started by: dharmesht
5 Replies
Login or Register to Ask a Question