Move part of a sequence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move part of a sequence
# 1  
Old 08-05-2014
Move part of a sequence

Hi there,

How I can do to move part of a sequence of files? For example:

I have this sequence
Code:
file.00001.jpg
file.00002.jpg
file.00003.jpg
....
file.05000.jpg

and I want to move the file file.00200.jpg to file.00010.jpg.

Thanks,

Last edited by Don Cragun; 08-05-2014 at 07:55 PM.. Reason: Add CODE tags.
# 2  
Old 08-05-2014
I must be missing the point:
Code:
mv file.00200.jpg file.00010.jpg


Last edited by Don Cragun; 08-06-2014 at 10:12 PM.. Reason: fix typo in filename (jpb -> jpg)
# 3  
Old 08-05-2014
Sorry for my english.

What I meant is to move all files between file.00010.jpg and file.00200.jpg, inclusive.

Sorry for not use the tag CODE.

Thanks.
# 4  
Old 08-05-2014
Is the idea to rename file.00200.jpg through file.05000.jpg to file.00010.jpg to the end of the list, or just file.00200.jpg through file.00389.jpg to file.00010.jpg through 00199.jpg?

What is supposed to happen if some files in the source or target range are missing? (Is the the next source file (numerically) to be moved instead, or is hole supposed to be left in the target sequence?)
# 5  
Old 08-06-2014
what do you want to do with these files
Do you want to rename them to something else in the same directory
or do you want to move them to some other folder
Below is the code to move such files to other directory /move/to/this/path/
Code:
ls -1 | awk '{split($0, a, "."); if(a[2]+0 >= 10 && a[2]+0 <= 200) print}' | while read line
do
mv ${line} /move/to/this/path/
done


Last edited by SriniShoo; 08-06-2014 at 12:17 AM.. Reason: change tags from ICODE to CODE
# 6  
Old 08-06-2014
Thanks,

Yes, I want to move to other directory.

---------- Post updated 07-08-14 at 02:34 AM ---------- Previous update was 06-08-14 at 11:34 AM ----------

Sorry for my English.
I can not get the script work properly.
How I can make it work with variables for start file, end file and destination?
I've tried this code and it does not work.

I run script like this:
Code:
./move.sh start end destination

And move.sh contains:
Code:
#!/bin/tcsh -f
ls -1 | awk '{split($0, a, "."); if(a[2]+0 >= $1 && a[2]+0 <= $2) print}' | while read line
do
mv ${line} $3
done



what is it wrong?

Thanks,
# 7  
Old 08-06-2014
You're mixing awk variables and shell variables. And, that is not the correct format for a tcsh while loop.

Try something more like:
Code:
#!/bin/ksh
ls file.*.jpg | awk -F '[.]' -v min="$1" -v max="$2" '{if($2+0 >= min && $2+0 <= max) print}' | while read line
do      mv "$line" "$3"
done

If you don't like the Korn shell, you can substitute any shell that recognizes basic Bourne shell syntax.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

How to move files with first part as new filenamevia bash shell scripting?

I am on linux red hat, want to use the logic within bash shell script file. I have the following type, named files in folder /staging, want to move with new filename just the firstpart upto underscore, example 20180904105056.dat, how can i get upto first part of filename and validate to chk if... (2 Replies)
Discussion started by: cplusplus1
2 Replies

3. Red Hat

Rm -rf * sequence

If I run rm -rf * command under one parent directory. /data > rm -rf * Is there anyway to know which files will be deleted first ? Start using code tags please, ty. (2 Replies)
Discussion started by: sameermohite
2 Replies

4. Shell Programming and Scripting

Sequence generator

Thanks Guys This really helped (5 Replies)
Discussion started by: robert89
5 Replies

5. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

6. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

7. Shell Programming and Scripting

comparing part of header with part of detailed records.

Hi there, I am lil confused with the following issue. I have a File, which has the following header: IMSHRATE_043008_101016 a sample detailed record is :9820101 A982005000CAVG030108000000000000010169000MAR 2008 9820102 MAR 2008 D030108 ... (1 Reply)
Discussion started by: cmaroju
1 Replies

8. Shell Programming and Scripting

escape sequence for $

Hi all, I have a requirement where the variable name starts with $, like $Amd=/home/student/test/ How to work wit it? can some one help me, am in gr8 confusion:confused: (5 Replies)
Discussion started by: shreekrishnagd
5 Replies

9. UNIX for Advanced & Expert Users

CVS: move part of repository (branch) to SVN server

Hi all, We have CVS server running for few years with absolutely no problems. Because of conditions not depending on me, I'm forced to move some part of our repository to another server (SVN). I need to move ONLY one branch from CVS server to SVN server. The branch must be moved with all... (7 Replies)
Discussion started by: +Yan
7 Replies

10. Solaris

STOP A sequence

Hi, I have a sun sparc system. I don't have a sun keyboard, hence i connected a pc keyboard. I would like to know the "STOP A" equivalent command to be used on pc keyboard. Regards, Raja (4 Replies)
Discussion started by: RajaRC
4 Replies
Login or Register to Ask a Question