Now what I would like is that the new renamed file looks like this so that it computes the mean of the last two values in first set ; for example
K2_34625-34675 should become K2_34650 and so on for the other names in the first set,
then these new names have to be used to rename the second set of files for example ;
U_P_321_9_3_11.ab1 should become K2_36450.ab1, and so on.
Could anyone please help out on this as I have a long list like this.
Hope to get some answers
Thanx in advance
Pawan
---------- Post updated 03-11-11 at 04:30 AM ---------- Previous update was 03-10-11 at 04:02 PM ----------
Thank you moderator for correcting my input .... I was not aware of such a thing as code tag.
Hope now the input is OK for a reply from the forum.
[ctsgnb@shell ~/sand]$ cat f1
K2_34625-34675
K7_988963-988983
K12_773882-7734102
[ctsgnb@shell ~/sand]$ cat f2
U_P_321_9_3_11.ab1
U_P_322_9_3_11.ab1
U_P_323_9_3_11.ab1
[ctsgnb@shell ~/sand]$ paste f2 f1 | while read a b
> do
> t=${b##*_???}
> v=$(echo $b | sed 's/.*_...//;s/-.../-/')
> n=${b%$t}$(( -($v) )).${a#*.}
> echo "mv $a $n"
> done
mv U_P_321_9_3_11.ab1 K2_34650.ab1
mv U_P_322_9_3_11.ab1 K7_98820.ab1
mv U_P_323_9_3_11.ab1 K12_7733220.ab1
[ctsgnb@shell ~/sand]$
If it does what you want then just change the echo "mv $a $n" with mv "$a $n"
---------- Post updated at 12:42 AM ---------- Previous update was at 12:34 AM ----------
please give more clue about the caculation for the renaming :
34625-34675 = -50
and what should be calculated in the
773882-7734102
????
I assumed you want to keep the first 3 number unchanged so that is becomes:
-(882-4102)=3220
so the new name will be K12_7733220.ab1
by the way, i also assume you have the same number of entries in your both set of files
Thanks CTSGNB,
Your suggestion is producing the exact output as you mentioned, but my expected outcome for input is as follows
input
K2_34625-34675
U_P_321_9_3_11.ab1
output before calculation
K2_34625-34675.ab1
For the calculation I want to calculate the mean of the two numbers separated by "-" which does not imply subtraction. Thus my final expected output for each entry in both set of files should be for example:
K2_34650.ab1
Please not the one set of entries are just assigned names eg. K2_34625-34675 upon which the calculation need to be done and then assigned the modified name to another entry (those ending with .ab1) which are real data containing files to be renamed.
> mv $a $n> done
mv: rename U_P_321_9_3_11.ab1 to K2_34650.ab1: No such file or directory
mv: rename U_P_322_9_3_11.ab1 to K7_988973.ab1: No such file or directory
mv: rename U_P_323_9_3_11.ab1 to K12_4253992.ab1: No such file or directory
-bash: () / 2 : syntax error: operand expected (error token is ") / 2 ")
Is this because a.txt and b.txt in this case are files containing entries and not real .ab1 files ??
I will do this will real files soons and let you know but if you can comment on the code to simplfy what its doing its will be a big help. At the moment I dont understand it
Yes all my U_P*.ab1 files are located in the same directory.
Although all my K*-* names are located in a different file.
I'm still having problems to figure this out. So to clarify, K*-* names are stored as a .txt file, and these nales have to be used to rename the U_P*.ab1 files to give rise to renamed K*-*.ab1 files.
Thank you for your help and input.
Have a nice day
---------- Post updated at 05:35 AM ---------- Previous update was at 05:33 AM ----------
Correction in previous reply :
I'm still having problems to figure this out. So to clarify, K*-* names are stored as a .txt file, and these nales (names) have to be used to rename the U_P*.ab1 files to give rise to renamed K*-*.ab1 files.
Please give more infos :
give the full PATH of WHERE all your K* and U*.ab1 files are located as well as WHERE your .txt files are located (those which contain the lists of their K and U*.ab1 names)
and use ksh when running the code i provide.
Please also provide what output you have when running the following command :
uname -a
---------- Post updated at 12:54 PM ---------- Previous update was at 12:53 PM ----------
Ok then try this :
cd /Users/pawannoel/Desktop
ksh
MYDIR=/Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results
paste b.txt a.txt | while read a b
do
t=${b##*_}
v=$(echo $b | sed 's/.*_//;s/-/+/')
n=${b%$t}$(( ($v) / 2 )).${a#*.}
mv "$MYDIR/$a $MYDIR/$n"
done
---------- Post updated at 01:01 PM ---------- Previous update was at 12:54 PM ----------
You shouldn't get errors ... except if some files mentionned in *.txt does not exist in
I'm afraid, due to data protection I cant provide you my machine ID as I am on an institutional machine, but I am getting the following results after your script
Notice that I am trying to work inside the "test" directory in the MYDIR path
u830-tro-6-35-6647:~ pawannoel$ ksh
$ MYDIR=/Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test
$ paste b.txt a.txt | while read a b
> do
> t=${b##*_}
> v=$(echo $b | sed 's/.*_//;s/-/+/')
> n=${b%$t}$(( ($v) / 2 )).${a#*.}
> mv "$MYDIR/$a $MYDIR/$n"
> done
paste: b.txt: No such file or directory
$
Both a.txt and b.txt are on the Desktop and look like this
1) Your .txt files should be in /Users/pawannoel/Desktop
2) Your U.ab1 should be in /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results
3) Then run the following :
cd /Users/pawannoel/Desktop
ksh
MYDIR=/Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results
unset t v n
paste ./b.txt ./a.txt | while read a b
do
t=${b##*_}
v=$(echo $b | sed 's/.*_//;s/-/+/')
n=${b%$t}$(( ($v) / 2 )).${a#*.}
mv "$MYDIR/$a $MYDIR/$n"
done
---------- Post updated at 02:26 PM ---------- Previous update was at 02:19 PM ----------