[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 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=$'\n'
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


Reply to: