Computing.Net > Forums > Unix > shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

shell script

Reply to Message Icon

Name: JANET
Date: December 3, 2002 at 11:23:02 Pacific
OS: win xp pro
CPU/Ram: 2gig/255ddram
Comment:

i need a simple shell script for unix, however im completely useless at shell scripting and cant get past the #!/bin/sh bit 8(....

what i desperately need to do is move files from my current directory into subdirectories depending on the first letter of its name, (eg.Accounts/A54mJU would be put into a subdirectory called A).

Subdirectories should only be created if there's files to be put into them (ie. no empty subdirectories)

and last of all a file called catalogue.txt should be created in my current directory listing all of the files which have been relocated, grouped by letter....

if any answers or help can be given i would be forever grateful...

thanks... Janet



Sponsored Link
Ads by Google

Response Number 1
Name: dineshnegi
Date: December 4, 2002 at 00:42:23 Pacific
Reply:

janetProblemSolved.pl this is a perl script which takes the absolute path of the directory for which subdirectories are to formed only care to be taken is that ther should be no file with a single letter as a name
i hope this serves ur purpose
art -----------------
#!/usr/local/bin/perl -w

my $dir = shift ;
chomp $dir ;
my %catalogue=();
my $add=();
opendir (HANDLE, "$dir") or die " cant open the directory file \n";
@files = readdir(HANDLE);
$countFiles = scalar(@files);
close HANDLE;
for($i = 2; $i >$dir/catalogue.txt") or die " cant open the file to write \n";
foreach $letter ( sort keys %catalogue) {
print FILE "files for letter $letter \n";
foreach $document ( @{$catalogue{$letter}}) {
print FILE " $document \n";
}
}

close FILE ;
close HANDLE;
-----


0
Reply to Message Icon

Related Posts

See More


Folder Permissions Questi... script required



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: shell script

Shell Scripting www.computing.net/answers/unix/shell-scripting/8475.html

Variables in Shell SCripting www.computing.net/answers/unix/variables-in-shell-scripting/6020.html

shell script to uninstall java www.computing.net/answers/unix/shell-script-to-uninstall-java-/5976.html