[SLE] What application or script language?
Hello SuSE folks, Could somebody tell me what application or script language is better to use to achieve the folowing tasks: 1. We have the directory with "xdir_name" name 2. In this directory we have files with "xdir_name_xfile_name". 3. In the first line each file has a header with "xdir_name" line. The question is how to automatically compare file header "xdir_name" to directory name "xdir_name" and if the file header doesn't match change it accordingly to the directory name where it is stored. Thanks in advance for any help. Alex -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
Alex Daniloff wrote:
Hello SuSE folks, Could somebody tell me what application or script language is better to use to achieve the folowing tasks: 1. We have the directory with "xdir_name" name 2. In this directory we have files with "xdir_name_xfile_name". 3. In the first line each file has a header with "xdir_name" line. The question is how to automatically compare file header "xdir_name" to directory name "xdir_name" and if the file header doesn't match change it accordingly to the directory name where it is stored. Thanks in advance for any help. Alex
It would be quite easy to write in perl. I could help you if you like.
Assuming that these are text files (and quite small), something like this
might work. Well it is completely untested. Other people - feel free
to critisize.
#!/usr/bin/perl
cd "xdir_name"
while ($file =
At 09:50 PM 6/9/00, Stephen Montgomery-Smith wrote:
Alex Daniloff wrote:
Hello SuSE folks, Could somebody tell me what application or script language is better to
use to
achieve the folowing tasks: 1. We have the directory with "xdir_name" name 2. In this directory we have files with "xdir_name_xfile_name". 3. In the first line each file has a header with "xdir_name" line. The question is how to automatically compare file header "xdir_name" to directory name "xdir_name" and if the file header doesn't match change it accordingly to the directory name where it is stored. Thanks in advance for any help. Alex
It would be quite easy to write in perl. I could help you if you like. Assuming that these are text files (and quite small), something like this might work. Well it is completely untested. Other people - feel free to critisize.
#!/usr/bin/perl
cd "xdir_name" while ($file =
) { $file =~ /xdir_name_(.*)/; $name = $1; open(FILE,$file) || die "Couldn't open file $file $!"; $first_line = <FILE>; $rest = join '',<FILE>; close FILE; open(FILE,"> $file") || die "Couln't write to file $file $!"; print FILE "$name\n$rest"; close FILE; }
Overhead can be reduced by moving the file instead of copying. Note that I
dropped the
$file =~ /xdir_name_(.*)/ line. It is not relevant to the logic as I see
it. An enhanced version may look like this:
# Move a file to the directory pointed to by it's very first line.
while ($d=
Actually our programs do different things. My program changes the header in the file to match the name of the file. Your program changes the name of the file to match the header of the file.
#!/usr/bin/perl
cd "xdir_name" while ($file =
) { $file =~ /xdir_name_(.*)/; $name = $1; open(FILE,$file) || die "Couldn't open file $file $!"; $first_line = <FILE>; $rest = join '',<FILE>; close FILE; open(FILE,"> $file") || die "Couln't write to file $file $!"; print FILE "$name\n$rest"; close FILE; } while ($d=
) { while ($f = <$d/xfile_.*>) { open (F, $f) || (next, die "Can't open $f ($!)\n"; $firstline = <F>; close (F); chomp $firstline; ($firstline ne $d) && (rename ($f, "$firstline/$f") || die "Can't move $f to $firstline/$f ($!)\n"); } }
-- Stephen Montgomery-Smith Department of Mathematics, University of Missouri, Columbia, MO 65211 Phone 573-882-4540, fax 573-882-1869 http://www.math.missouri.edu/~stephen stephen@math.missouri.edu -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
participants (3)
-
alex@daniloff.com
-
koos.pol@nl.compuware.com
-
stephen@math.missouri.edu