|
Home > Archive > Unix Shell > February 2007 > Range File copy
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Is there a way to copy all the files between two particular number?
( In this example given below from 1030 - 2210)
I have flat files
abc.001021.dat
abc.001049.dat
abc.001033.dat
abc.001234.dat
abc.001345.dat
abc.001608.dat
..
..
..
abc.0002210.dat
Thanks in advance.
| |
| Chris F.A. Johnson 2007-02-22, 7:15 pm |
| On 2007-02-22, vp wrote:
> Is there a way to copy all the files between two particular number?
> ( In this example given below from 1030 - 2210)
>
> I have flat files
>
> abc.001021.dat
> abc.001049.dat
> abc.001033.dat
> abc.001234.dat
> abc.001345.dat
> abc.001608.dat
> .
> .
> .
> abc.0002210.dat
In bash3:
cp abc.00{1049..1345}.dat /path/to/new/directory 2>/dev/null
Otherwise:
list=
NL='
'
n=1049
last=1345
while [ $n -le $last ]
do
num=000000$n
fn=abc.${num#"${num%??????}"}.dat
[ -f "$fn" ] && list=$list${NL}$fn
n=$(( $n + 1 ))
done
cp $list /path/to/new/directory
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Michael Tosch 2007-02-23, 1:18 pm |
| vp wrote:
> Is there a way to copy all the files between two particular number?
> ( In this example given below from 1030 - 2210)
>
> I have flat files
>
> abc.001021.dat
> abc.001049.dat
> abc.001033.dat
> abc.001234.dat
> abc.001345.dat
> abc.001608.dat
> .
> .
> .
> abc.0002210.dat
>
cp `\ls | awk -F. '$2>=1030 && $2<=2210'` /path/to/new/directory
Try with echo first, then with cp.
--
Michael Tosch @ hp : com
|
|
|
|
|