🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.comp.linux.isp
7 messages
7 total messages Started by Laplace Wed, 29 Jan 2003 21:51
help in linux shell script in copying files
#6
Author: Laplace
Date: Wed, 29 Jan 2003 21:51
17 lines
1660 bytes
if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
finished A
if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
finished A to Z....

algorithm

if the "first letter is "A" or "a" copy it from \temp\  to \data\A\....

if the "first letter is "B" or "b" copy it from \temp\ to \data\B\....




up to Z....

can u show me the script?
Re: help in linux shell script in copying files
#7
Author: Val V. Polyakov
Date: Wed, 29 Jan 2003 22:12
29 lines
1976 bytes
mmmm.
the smell of homework.


On Thu, 30 Jan 2003, Laplace wrote:

> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A to Z....
>
> algorithm
>
> if the "first letter is "A" or "a" copy it from \temp\  to \data\A\....
>
> if the "first letter is "B" or "b" copy it from \temp\ to \data\B\....
>
>
>
>
> up to Z....
>
> can u show me the script?
>
>
>
>
>
>
Re: help in linux shell script in copying files
#8
Author: John W. Krahn
Date: Wed, 29 Jan 2003 22:34
44 lines
2320 bytes
Laplace wrote:
> 
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A to Z....
> 
> algorithm
> 
> if the "first letter is "A" or "a" copy it from \temp\  to \data\A\....
> 
> if the "first letter is "B" or "b" copy it from \temp\ to \data\B\....
> 
> up to Z....
> 
> can u show me the script?


#!/usr/bin/perl -w
use strict;
use File::Copy;

my $from = '/temp';
my $to   = '/data';

opendir my $dh, $from or die "Cannot open '$from' $!";

while ( defined( my $file = readdir $dh ) ) {
    next unless $file =~ /^([[:alpha:]])/;
    my $first = uc $1;
    mkdir "$to/$first" unless -e "$to/$first";
    copy( "$from/$file", "$to/$first/$file" )
        or warn "Cannot copy $file to $to/$first: $!";
    }

__END__



John
-- 
use Perl;
program
fulfillment
Re: help in linux shell script in copying files
#9
Author: Gerhard W. Gruber
Date: Wed, 29 Jan 2003 22:51
29 lines
2329 bytes
On Thu, 30 Jan 2003 05:51:25 +0800 wrote "Laplace" <Laplace@tranforms.org> in
comp.os.linux.misc with <b19idc$mb42@imsp212.netvigator.com>

>if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
>finished A
>if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
>finished A to Z....
>
>algorithm
>
>if the "first letter is "A" or "a" copy it from \temp\  to \data\A\....
>
>if the "first letter is "B" or "b" copy it from \temp\ to \data\B\....
>
>
>
>
>up to Z....
>
>can u show me the script?

cd /temp; ls | while read f; do FIRST=`echo "$f" | cut -c1 | tr "[a-z]"
"[A-Z]"`: mv "$f" "/data/$FIRST/$f"; done

-- 
Gerhard Gruber

F�r jedes menschliche Problem gibt es immer eine einfache L�sung:
Klar, einleuchtend und falsch. (Henry Louis Mencken)
Re: help in linux shell script in copying files
#10
Author: Luke Vogel
Date: Wed, 29 Jan 2003 22:55
5 lines
1574 bytes
> can u show me the script?

Not in a security forum ...

Idiot cross posters ...
Re: help in linux shell script in copying files
#11
Author: Michael Heiming
Date: Wed, 29 Jan 2003 23:28
27 lines
2245 bytes
In comp.os.linux.misc Laplace <Laplace@tranforms.org> wrote:
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A
> if the "first letter is "A" or "a" copy it from \temp\ to \data\A\.... until
> finished A to Z....

Where do you see all those backslahes?

> up to Z....

> can u show me the script?

Script? 

$ ls | awk '/^[A-z]/{d=toupper(substr($1,1,1));system("cp "$1" "d"/")}'

(No error checking at all, better use 'find')

However, if this is homework, I wouldn't suggest showing up something 
like this.

Please reduce cross-posting, to reasonable groups.

Michael Heiming
-- 
Remove +SIGNS and www. if you expect an answer, sorry for 
inconvenience, but I get tons of SPAM
Re: help in linux shell script in copying files
#12
Author: Kirk Strauser
Date: Wed, 29 Jan 2003 23:30
19 lines
2388 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2003-01-29T22:51:43Z, Gerhard W. Gruber <sparhawk@gmx.at> writes:

> cd /temp; ls | while read f; do FIRST=`echo "$f" | cut -c1 | tr "[a-z]"
> "[A-Z]"`: mv "$f" "/data/$FIRST/$f"; done

Be careful!  He'll lose homework points if any filenames start with [^a-zA-Z].
- -- 
Kirk Strauser
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+OF/f5sRg+Y0CpvERAtbGAJ92p+ZADMCp+WePks3VmfbI4L4ZMQCgiiB/
7IF4Rfs2LhNjgnWSK5pFrnM=
=j6Nl
-----END PGP SIGNATURE-----
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads