Renaming files in one file from names in other


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Renaming files in one file from names in other
# 15  
Old 03-14-2011
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 :

Code:
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 ----------

On which OS are you ?

Last edited by ctsgnb; 03-14-2011 at 10:25 AM..
# 16  
Old 03-14-2011
It worked partially ..... It didnt rename the first .ab1 file.

Also the "" in the mv command leads to error so I removed them and ran your commands

So the list below was before renaming
Code:
U3244_AN_PN_11_03_11_1_A08_002.ab1    U3244_AN_PN_11_03_11_2_B08_004.ab1  
U3244_AN_PN_11_03_11_3_C08_006.ab1 U3244_AN_PN_11_03_11_4_D08_008.ab1    U3244_AN_PN_11_03_11_5_E08_010.ab1
U3244_AN_PN_11_03_11_6_F08_012.ab1
U3244_AN_PN_11_03_11_7_G08_014.ab
U3244_AN_PN_11_03_11_8_H08_016.ab11

The list after renaming is

Code:
K7_S5_1083864.ab1                     
K7_S6_1083864.ab1                        
K7_S6_280190.ab1           
K7_S7_1083864.ab1 
K7_S7_280190.ab1
K7_S8a_1083864.ab1 
K7_S8a_280190.ab1
U3244_AN_PN_11_03_11_1_A08_002.ab1

I'm using OSX 10.5.8

thnx, we are nearly there with this ... appreciate your help Smilie
# 17  
Old 03-14-2011
what gives :

Code:
cd /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results
ls | grep ' '


?
what gives
Code:
ls -F

?
This User Gave Thanks to ctsgnb For This Post:
# 18  
Old 03-14-2011
ls | grep ' ' gives:

Code:
K7_S5_1083864.ab1
K7_S6_1083864.ab1
K7_S6_280190.ab1
K7_S7_1083864.ab1
K7_S7_280190.ab1
K7_S8a_1083864.ab1
K7_S8a_280190.ab1
U3244_AN_PN_11_03_11_1_A08_002.ab1

ls -F gives:

Code:
K7_S5_1083864.ab1*            K7_S6_280190.ab1*            K7_S7_280190.ab1*            K7_S8a_280190.ab1*
K7_S6_1083864.ab1*            K7_S7_1083864.ab1*            K7_S8a_1083864.ab1*            U3244_AN_PN_11_03_11_1_A08_002.ab1*

# 19  
Old 03-14-2011
please provide :

Code:
cat /Users/pawannoel/Desktop/a.txt
cat /Users/pawannoel/Desktop/b.txt
cat b.txt | xargs -i ls /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/{}

run this :

Code:
ksh
cd /Users/pawannoel/Desktop
unset t v n
MYDIR=/Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results
paste ./b.txt ./a.txt | while read a b
do
[[ ! -f "$MYDIR/$a" ]] && echo "$MYDIR/$a does not exists, script abort" && break
echo "before assignment t=$t v=$v n=$n a=$a b=$b"
t=${b##*_}
v=$(echo $b | sed 's/.*_//;s/-/+/')
n=${b%$t}$(( ($v) / 2 )).${a#*.}
echo "before mv t=$t v=$v n=$n a=$a b=$b"
echo "mv $MYDIR/$a $MYDIR/$n"
mv "$MYDIR/$a" "$MYDIR/$n"
unset t v n
echo "after unset t=$t v=$v n=$n a=$a b=$b"
done

And copy paste the output you will get
# 20  
Old 03-14-2011
Code:
u830-tro-6-35-6647:~ pawannoel$ cat /Users/pawannoel/Desktop/a.txt
K7_S5_279891-280489
K7_S6_279891-280489
K7_S7_279891-280489
K7_S8a_279891-280489
K7_S5_1083565-1084163
K7_S6_1083565-1084163
K7_S7_1083565-1084163
K7_S8a_1083565-1084163
u830-tro-6-35-6647:~ pawannoel$ cat /Users/pawannoel/Desktop/b.txt
U3244_AN_PN_11_03_11_1_A08_002.ab1
U3244_AN_PN_11_03_11_2_B08_004.ab1
U3244_AN_PN_11_03_11_3_C08_006.ab1
U3244_AN_PN_11_03_11_4_D08_008.ab1
U3244_AN_PN_11_03_11_5_E08_010.ab1
U3244_AN_PN_11_03_11_6_F08_012.ab1
U3244_AN_PN_11_03_11_7_G08_014.ab1
U3244_AN_PN_11_03_11_8_H08_016.ab1
u830-tro-6-35-6647:~ pawannoel$ cat b.txt | xargs -i ls /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/{}
cat: b.txt: No such file or directory
xargs: illegal option -- i
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]

u830-tro-6-35-6647:Desktop pawannoel$ ksh
$ cd /Users/pawannoel/Desktop
$ unset t v n
$ MYDIR=/Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test
$ paste ./b.txt ./a.txt | while read a b
> do
> [[ ! -f "$MYDIR/$a" ]] && echo "$MYDIR/$a does not exists, script abort" && break
> echo "before assignment t=$t v=$v n=$n a=$a b=$b"
> t=${b##*_}
> v=$(echo $b | sed 's/.*_//;s/-/+/')
> n=${b%$t}$(( ($v) / 2 )).${a#*.}
> echo "before mv t=$t v=$v n=$n a=$a b=$b"
> echo "mv $MYDIR/$a $MYDIR/$n"
> mv "$MYDIR/$a" "$MYDIR/$n"
> unset t v n
> echo "after unset t=$t v=$v n=$n a=$a b=$b"
> done
before assignment t= v= n= a=U3244_AN_PN_11_03_11_1_A08_002.ab1 b=K7_S5_279891-280489
before mv t=279891-280489 v=279891+280489 n=K7_S5_280190.ab1 a=U3244_AN_PN_11_03_11_1_A08_002.ab1 b=K7_S5_279891-280489
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_1_A08_002.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S5_280190.ab1
mv: mv: cannot execute [Exec format error]
after unset t= v= n= a=U3244_AN_PN_11_03_11_1_A08_002.ab1 b=K7_S5_279891-280489
before assignment t= v= n= a=U3244_AN_PN_11_03_11_2_B08_004.ab1 b=K7_S6_279891-280489
before mv t=279891-280489 v=279891+280489 n=K7_S6_280190.ab1 a=U3244_AN_PN_11_03_11_2_B08_004.ab1 b=K7_S6_279891-280489
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_2_B08_004.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S6_280190.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_2_B08_004.ab1 b=K7_S6_279891-280489
before assignment t= v= n= a=U3244_AN_PN_11_03_11_3_C08_006.ab1 b=K7_S7_279891-280489
before mv t=279891-280489 v=279891+280489 n=K7_S7_280190.ab1 a=U3244_AN_PN_11_03_11_3_C08_006.ab1 b=K7_S7_279891-280489
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_3_C08_006.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S7_280190.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_3_C08_006.ab1 b=K7_S7_279891-280489
before assignment t= v= n= a=U3244_AN_PN_11_03_11_4_D08_008.ab1 b=K7_S8a_279891-280489
before mv t=279891-280489 v=279891+280489 n=K7_S8a_280190.ab1 a=U3244_AN_PN_11_03_11_4_D08_008.ab1 b=K7_S8a_279891-280489
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_4_D08_008.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S8a_280190.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_4_D08_008.ab1 b=K7_S8a_279891-280489
before assignment t= v= n= a=U3244_AN_PN_11_03_11_5_E08_010.ab1 b=K7_S5_1083565-1084163
before mv t=1083565-1084163 v=1083565+1084163 n=K7_S5_1083864.ab1 a=U3244_AN_PN_11_03_11_5_E08_010.ab1 b=K7_S5_1083565-1084163
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_5_E08_010.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S5_1083864.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_5_E08_010.ab1 b=K7_S5_1083565-1084163
before assignment t= v= n= a=U3244_AN_PN_11_03_11_6_F08_012.ab1 b=K7_S6_1083565-1084163
before mv t=1083565-1084163 v=1083565+1084163 n=K7_S6_1083864.ab1 a=U3244_AN_PN_11_03_11_6_F08_012.ab1 b=K7_S6_1083565-1084163
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_6_F08_012.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S6_1083864.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_6_F08_012.ab1 b=K7_S6_1083565-1084163
before assignment t= v= n= a=U3244_AN_PN_11_03_11_7_G08_014.ab1 b=K7_S7_1083565-1084163
before mv t=1083565-1084163 v=1083565+1084163 n=K7_S7_1083864.ab1 a=U3244_AN_PN_11_03_11_7_G08_014.ab1 b=K7_S7_1083565-1084163
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_7_G08_014.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S7_1083864.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_7_G08_014.ab1 b=K7_S7_1083565-1084163
before assignment t= v= n= a=U3244_AN_PN_11_03_11_8_H08_016.ab1 b=K7_S8a_1083565-1084163
before mv t=1083565-1084163 v=1083565+1084163 n=K7_S8a_1083864.ab1 a=U3244_AN_PN_11_03_11_8_H08_016.ab1 b=K7_S8a_1083565-1084163
mv /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/U3244_AN_PN_11_03_11_8_H08_016.ab1 /Users/pawannoel/Documents/Sequences/Sanger_Sequencing_results/test/K7_S8a_1083864.ab1
after unset t= v= n= a=U3244_AN_PN_11_03_11_8_H08_016.ab1 b=K7_S8a_1083565-1084163

# 21  
Old 03-14-2011

this error
cannot execute [Exec format error]

is very strange, i saw that there are some thread about similar error message on Apple forum.

Apple - Support - Discussions - Intermittent "cannot execute [Exec ...
and
Apple - Support - Discussions - Intermittent "cannot execute [Exec ...

looks like an OS bug
, maybe you should consider upgrading/patching your OS
This User Gave Thanks to ctsgnb For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming the file names in a directory

Hi, I have about 60 files in a directory and need to rename those files. For example the file names are i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc) i_usa_phone_1_yymmdd.txt i_eng_phone_4_yymmdd.txt The new file names should be phone.txt phone_1.txt phone_4.txt I am... (4 Replies)
Discussion started by: naveed
4 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Shell Programming and Scripting

Renaming File Names in a folder/Dir

Hi Team, I'm new to Unix shell scripting . I've the following requirement A folder contains the list of files with the following format ab.name.11.first ab.name.12.second ab.name.13.third ---------- I have to rename the above file to like below ... (6 Replies)
Discussion started by: smile689
6 Replies

4. UNIX for Dummies Questions & Answers

Renaming files with weird names

I have hundreds of files with weird names, something like this: I was wondering how can I rename them all keeping the sampleid and the last extension, something like this: Any help will be greatly appreciated. (5 Replies)
Discussion started by: Xterra
5 Replies

5. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

6. Shell Programming and Scripting

Renaming file names

I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (2 Replies)
Discussion started by: vpv0002
2 Replies

7. Shell Programming and Scripting

renaming files from an array of names

I haven’t used Unix in over 25 years … and so I am at a loss for something that should be very simple. I have a lot of jpeg files (i.jpg) of students in a yearbook.. I also have an array name(i) of their names. I need to rename each “i.jpg” to “name(i).jpg”. I believe the ksh script... (11 Replies)
Discussion started by: chuckmg
11 Replies

8. Shell Programming and Scripting

File renaming from list of names contained in another file

I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile). The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be... (7 Replies)
Discussion started by: netfreighter
7 Replies

9. UNIX for Dummies Questions & Answers

Some questions - renaming duplicate names

I have a file that looks like this 2 4 10 500 tim9 5 8 14 700 tim9 3 5 15 432 john1 1 4 12 999 ellen2 So basically what i want to do is fine duplicate names on column 5 and rename it with an extention (i.e. tim9_1 and tim9_2). so the output file will look like this 2 4 10 500 tim9_1... (1 Reply)
Discussion started by: kylle345
1 Replies

10. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies
Login or Register to Ask a Question