rehman
rehman

Reputation: 101

Combine the two files having common string in file name into a new file

I have many files as given below, here I want two similar files name should copy to new file

LBTB.BHZ.2013...13.18.58.940.00.sac.DEC.dsp  
LBTB.BHZ.2013...13.18.58.940.00.sac.DEC.dsp.1
LBTB.BHZ.2013...14.09.18.040.00.sac.DEC.dsp  
LBTB.BHZ.2013...14.09.18.040.00.sac.DEC.dsp.1
LBTB.BHZ.2013...14.34.56.830.00.sac.DEC.dsp  
LBTB.BHZ.2013...14.34.56.830.00.sac.DEC.dsp.1
LBTB.BHZ.2013...16.07.16.970.00.sac.DEC.dsp  
LBTB.BHZ.2013...16.07.16.970.00.sac.DEC.dsp.1
LBTB.BHZ.2013...16.59.49.440.00.sac.DEC.dsp  
LBTB.BHZ.2013...16.59.49.440.00.sac.DEC.dsp.1

I want to cat LBTB.BHZ.2013...13.18.58.940.00.sac.DEC.dsp  LBTB.BHZ.2013...13.18.58.940.00.sac.DEC.dsp.1 these two files to a new file LBTB.BHZ.2013...13.18.58.940.00.sac.DEC.dsp.DSP 
similar steps to be follwed to all file

I have tried below code

for file in *dsp *dsp.1; do

cat $file > $file.DSP

done

Upvotes: 0

Views: 47

Answers (1)

ypnos
ypnos

Reputation: 52337

What about this?

for file in *dsp; do
    cat $file $file.1 > $file.DSP
done

The glob will find always the first file of a file pair, so we loop over pairs instead of single files: In the cat arguments, we use the file's name to also compose its counterpart's name.

Upvotes: 1

Related Questions