Rodrigo Moya wrote:
> I've got a text file containing the following:
>
> /dir/file1=/mnt/zip/dir/file1
> /dir/dir/file2=/mnt/zip/dir/dir/file1
> ...
>
> and like this with hundreds of files. What I want is to read all the
> file and copy the files in the first position (to the left of '=') to
> the place specified by the string at the right of '='. But I don't know
> how to split the line from a shell script (as you guessed I'm quite bad
> at shell programming).
You could use sed to insert a "cp " at the beginning of each line then
replace the equals sign (=) with a space. The output would become a script
with all the desired copy commands, which can immediately be run by your
shell:
cat filelist.dat | sed -e "s/^/cp /" -e "s/=/ /" > ready2run.sh
bash ready2run.sh
Or you can use perl if you want to get fancy:
#!/usr/bin/perl
#
# Pipe the file lists into this script using something
# like this: this_script.pl < filelist.dat
#
while ($line = <STDIN>)
{
@filenames = split('=',$line);
$cmd = "cp $filenames[0] $filenames[1]";
print "copying $filenames[0] to $filenames[1]\n";
system($cmd);
}
Tony
--
Anthony E. Greene <[EMAIL PROTECTED]>
Homepage & PGP Key <http://www.pobox.com/~agreene/>
If it's too good to be true, it's probably Linux.
--
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.