FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 03-11-2009, 02:17 PM
Eduardo M KALINOWSKI
 
Default scripts for batch treatment

Bernard wrote:
> Hi to Everyone !
>
> I intend to copy a number of files chosen from a given directory. At
> first, I've made a mistake : instead of deleting unwanted files from a
> copy of said directory, I worked on deleting lines on a filelist that I
> had extracted
> using 'ls -l > filename.txt'. This sorting job, on about 12,500 lines,
> took several hours of my time, and I hope to find a way to make use of
> the result obtained, rather than re-doing the whole sorting job. The
> sorted files number about 400 or so. Had it been only 2 or 3 dozens of
> files, I would not have hesitated repeating the following command for
> each file :
>
> cp
> /mnt/exthd/home/bd/office52/user/desktop/etc/etc/filename_pasted_from_the_list
> /home/mydir
>
> But 400 files are too many, and I expect to be able to treat this, using
> some sort of a shell script suitable for batch treatment...
>
> A similar problem had occured to me 3 or 4 years ago for batch treatment
> of a series of picture files, and I had managed with a short Free Pascal
> routine using a 'for n=x to y do" loop, this being made possible by the
> fact that filenames were made of a rising set of numeric values, which
> is not the case for my new problem. Filenames are indeed made of long
> strings of characters since they are "subjects" of e-mails received via
> StarOffice 5.1 and 5.2.
>
> Thanks in advance for any hint.
>
> P.S. I know nothing about shell scripts, so I might need a good tutorial
> on this.
>

There's no need for shell scripting. Just use the commands available:

xargs -a list-of-files-to-copy -IFILE cp FILE /destination/path

--
spagmumps, n.:
Any of the millions of Styrofoam wads that accompany mail-order items.
-- "Sniglets", Rich Hall & Friends

Eduardo M KALINOWSKI
eduardo@kalinowski.com.br


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-11-2009, 03:05 PM
Jochen Schulz
 
Default scripts for batch treatment

Bernard:
>
> I intend to copy a number of files chosen from a given directory. At
> first, I've made a mistake : instead of deleting unwanted files from a
> copy of said directory, I worked on deleting lines on a filelist that I
> had extracted
> using 'ls -l > filename.txt'.

I am not sure I understand what you trying to do. Neither do I
understand what you did instead. If you just edited filename.txt in a
wrong way, whats preventing you from regenerating it?

> This sorting job,

Which sorting job? You didn't mention any sorting until now.

> on about 12,500 lines,
> took several hours of my time,

Whoah! You didn't sort 12,500 lines manually, did you? You could have
just used 'sort'. If your hardware isn't ancient, that shouldn't take
more than a few seconds.

> and I hope to find a way to make use of
> the result obtained, rather than re-doing the whole sorting job. The
> sorted files number about 400 or so. Had it been only 2 or 3 dozens of
> files, I would not have hesitated repeating the following command for
> each file :
>
> cp
> /mnt/exthd/home/bd/office52/user/desktop/etc/etc/filename_pasted_from_the_list
> /home/mydir

for f in $files; do
cp "/source/$f" /target/
done

> strings of characters since they are "subjects" of e-mails received via
> StarOffice 5.1 and 5.2.

Ouch. You might have problems with my solution if the subjects contain
weird characters. Spaces shoudl be fine, though.

> P.S. I know nothing about shell scripts, so I might need a good tutorial
> on this.

Advanced Bash-Scripting Guide.

J.
--
If I had to live on a desert island I would take a mobile phone,
preferably a Nokia 8810.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
 
Old 03-11-2009, 09:54 PM
Mart Frauenlob
 
Default scripts for batch treatment

Jochen Schulz wrote:

Bernard:

I intend to copy a number of files chosen from a given directory. At
first, I've made a mistake : instead of deleting unwanted files from a
copy of said directory, I worked on deleting lines on a filelist that I
had extracted

using 'ls -l > filename.txt'.



I am not sure I understand what you trying to do. Neither do I
understand what you did instead. If you just edited filename.txt in a
wrong way, whats preventing you from regenerating it?



This sorting job,



Which sorting job? You didn't mention any sorting until now.


on about 12,500 lines,
took several hours of my time,



Whoah! You didn't sort 12,500 lines manually, did you? You could have
just used 'sort'. If your hardware isn't ancient, that shouldn't take
more than a few seconds.



yes, sort sounds valuable
and I hope to find a way to make use of
the result obtained, rather than re-doing the whole sorting job. The
sorted files number about 400 or so. Had it been only 2 or 3 dozens of
files, I would not have hesitated repeating the following command for
each file :


cp
/mnt/exthd/home/bd/office52/user/desktop/etc/etc/filename_pasted_from_the_list
/home/mydir



for f in $files; do
cp "/source/$f" /target/
done


strings of characters since they are "subjects" of e-mails received via
StarOffice 5.1 and 5.2.



Ouch. You might have problems with my solution if the subjects contain
weird characters. Spaces shoudl be fine, though.



No, spaces are not fine in your example.
for f in $files <-- the word splitting already occurs here.
You'd need at least:

set -f
OIFS="$IFS"
IFS=$'
'
for f in $files; do
cp "/source/$f" "/target/"
done
IFS="$OIFS"
set +f

If you want to read from a file and the file already contains the list
of file names (one on each line), then I'd use a `while read` loop.


set -f
while read str_line; do
cp "${str_line}" "/target/"
done < <("${filename}")
set +f

set -f disables file name globbing and should help care about weird
characters in that case.

while read str_line reads a line by default, so no need to set IFS.

greets

Mart


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-11-2009, 10:18 PM
Mart Frauenlob
 
Default scripts for batch treatment

Mart Frauenlob wrote:

Jochen Schulz wrote:

Bernard:

I intend to copy a number of files chosen from a given directory.
At first, I've made a mistake : instead of deleting unwanted files
from a copy of said directory, I worked on deleting lines on a
filelist that I had extracted

using 'ls -l > filename.txt'.



I am not sure I understand what you trying to do. Neither do I
understand what you did instead. If you just edited filename.txt in a
wrong way, whats preventing you from regenerating it?



This sorting job,



Which sorting job? You didn't mention any sorting until now.



on about 12,500 lines, took several hours of my time,



Whoah! You didn't sort 12,500 lines manually, did you? You could have
just used 'sort'. If your hardware isn't ancient, that shouldn't take
more than a few seconds.



yes, sort sounds valuable
and I hope to find a way to make use of the result obtained, rather
than re-doing the whole sorting job. The sorted files number about
400 or so. Had it been only 2 or 3 dozens of files, I would not
have hesitated repeating the following command for each file :


cp
/mnt/exthd/home/bd/office52/user/desktop/etc/etc/filename_pasted_from_the_list
/home/mydir



for f in $files; do
cp "/source/$f" /target/
done


strings of characters since they are "subjects" of e-mails received
via StarOffice 5.1 and 5.2.



Ouch. You might have problems with my solution if the subjects contain
weird characters. Spaces shoudl be fine, though.



No, spaces are not fine in your example.
for f in $files <-- the word splitting already occurs here.
You'd need at least:

set -f
OIFS="$IFS"
IFS=$'
'
for f in $files; do
cp "/source/$f" "/target/"
done
IFS="$OIFS"
set +f

If you want to read from a file and the file already contains the list
of file names (one on each line), then I'd use a `while read` loop.


set -f
while read str_line; do
cp "${str_line}" "/target/"
done < <("${filename}")
set +f


sorry, error here: done < <("${filename}")
should be: done < "${filename}"
command substitution would be used like that:
done < <(cat "${filename}")

greets

Mart


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 04:30 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org