The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Move files yshahiac UNIX for Dummies Questions & Answers 3 02-13-2009 09:35 AM
move old files tjay83 Shell Programming and Scripting 26 08-15-2008 11:58 AM
how to move files monicasgupta Shell Programming and Scripting 1 03-14-2008 04:53 PM
How to move all files except one? Kim Walisch Shell Programming and Scripting 4 11-02-2007 05:00 PM
move files ust Shell Programming and Scripting 5 07-04-2005 03:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-24-2009
joey_reddy joey_reddy is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 4
Question move a set of files

Hi Everyone!!!

Is there any command to move/copy set of files in a specific range.

Eg :
I have 800 text files in a directory
A1 ... A800

I would like to copy only files in range A40 ... A250.
I can acheive this using a "for" loop , but I guess there could be some command or Identifier ( with sed/grep/cp) which I can use to do this.
Can somebody help !!!

Regards
JR
  #2 (permalink)  
Old 04-24-2009
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
how about:
Code:
for file in `perl -e 'for $n (40 .. 250) { print "A$n", "\n"; }'`; do echo moving file $file ... ; mv $file /somewhere/else/ ; done

  #3 (permalink)  
Old 04-24-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
Quote:
Originally Posted by joey_reddy View Post
Hi Everyone!!!

Is there any command to move/copy set of files in a specific range.

Eg :
I have 800 text files in a directory
A1 ... A800

I would like to copy only files in range A40 ... A250.
[...]
Which shell you are using (exact version if possible)?
  #4 (permalink)  
Old 04-27-2009
joey_reddy joey_reddy is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 4
I Use ksh , I am able to acheive the desired output using a simple for loop.

for (( i = 40; i <= 250; i++ )) ; do ; cp A$i /var/tmp ; done

However my Mind wants some command (like sed..) to give the output. Im sure there could be some command which can replace the above for loop.

Thanks to all the gurus who responded !!
  #5 (permalink)  
Old 04-27-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
It seems you're using ksh93, so you may use brace expansion:


Code:
cp A{40..250} /var/tmp

  #6 (permalink)  
Old 04-29-2009
joey_reddy joey_reddy is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 4
Thanks .. The cp command works very well for bash, but is not working on ksh ..

Can you please help me with a ksh version of the command.
  #7 (permalink)  
Old 04-29-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
What version of the Korn shell you are using?
You said you use a loop like this (which implies ksh93):


Code:
for (( i = 40; i <= 250; i++ )) ...



but the brace expansion doesn't appear to work (ksh88, pdksh or other variant) ...

If you have the old ksh88 and you don't want to use external tools, you will need something like this:


Code:
cp A@([4-9][0-9]|[12]@(50|[0-4][0-9]))  /var/tmp

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0