LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   showing section in files that have different names... (https://www.linuxquestions.org/questions/linux-newbie-8/showing-section-in-files-that-have-different-names-792975/)

Drigo 03-03-2010 03:58 PM

showing section in files that have different names...
 
I am running a bash script and I would like a command that will show me what differs from some files with similar names so I can delete them. Or if you can provide some info on how to complete my script. it will be great>
Here is my code:

#!/bin/bash


pwd=SOURCE

#Add extension into the name
for FILE in $( ls $SOURCE*$2*);
do echo $FILE;
if [ $1 = "-rename" ]; then
echo "renaming...."
#mv $FILE "${FILE//$1}";
elif [ $1 = "-replace" ]; then
echo "replacing...."
mv $FILE "${FILE/$2/$3}";

else
echo "deleting....";
#$2 at the beggining...
#mv $FILE $2_"${FILE//$1}";
# echo "to...." $2_"${FILE//$1}";
fi
done




This are the filenames under a directory:

11420_07_20090604.nii_Corrected.nii.gz 11420_16_20090914.nii_Corrected.nii.gz
11420_07R_20090604.nii_Corrected.nii.gz 11420_16R_20090914.nii_Corrected.nii.gz
11420_08_20090806.nii_Corrected.nii.gz 11420_17_20090928.nii_Corrected.nii.gz


This is what I want:

11420_07.nii.gz
11420_16.nii.gz
11420_07R.nii.gz
11420_16R.nii.gz
11420_08.nii.gz
11420_17.nii.gz

I want to get rid of the 2009XXX names that differ.
Thanks in advance!

smoker 03-03-2010 04:05 PM

man diff


All times are GMT -5. The time now is 08:21 PM.