Find two files of similar name which have different extention and copy to new location

Rahman_

New Member
Joined
Jul 25, 2019
Messages
2
Reaction score
0
Credits
0
I have a directory containing files as given below

PALK.BHZ.2010.10.31.12.23.42.350.10.sac.
PALK.BHZ.2010.10.31.12.23.42.350.10.sac..dsp
PALK.BHZ.2010.11.08.07.37.10.140.00.sac.
PALK.BHZ.2010.11.08.07.37.10.140.00.sac..dsp
PALK.BHZ.2010.11.08.07.37.10.140.10.sac.
PALK.BHZ.2010.11.08.12.28.34.430.00.sac.
PALK.BHZ.2010.11.08.12.28.34.430.10.sac.

I want to mv files of a similar name which have a different extension.
Like from above files I want to move below-given files to a new location.

PALK.BHZ.2010.10.31.12.23.42.350.10.sac.
PALK.BHZ.2010.10.31.12.23.42.350.10.sac..dsp
PALK.BHZ.2010.11.08.07.37.10.140.00.sac.
PALK.BHZ.2010.11.08.07.37.10.140.00.sac..dsp


So far I have tried below code, but the problem still remains

for file in *sac.; do
[ -f "$file" ] || continue
[ ! -e "${file%%.*}.dsp" ] && mv "$file" /home/gar
done
 


for f in *sac.; do same=("${f%.*}".*); [ "${#same[@]}" -eq 1 ] && mv "$f" /home/newtst ; done
 
[EDIT]
Ah - you solved it yourself while I was typing?! Never mind!
[/EDIT]
 
Last edited:

Members online


Top