[Digikam-users] Not completely but a bit off topic question: looking for texteditor with macro capabillity
Benjamin GIRAULT
benjamin.girault at gmail.com
Sat Aug 27 11:32:36 BST 2011
Hi Sleepless,
That is my first answer to this list, but I've been playing with the
linux command line for quite some years now.
2011/8/27 sleepless <sleeplessregulus at hetnet.nl>:
> for example you could do in dos ¨dir > dir.lst
To use such a list, you can use "$(ls)", or "$(ls <directory>)"...
> a list of
> d:\foto\digikam\photo.jpg
> then very easy make a macro to put in front ¨move ¨ ¨
... for example:
$ for f in $(ls); do move ${f} <target directory>; done
> then search for ¨\¨ then block and search twice again for ¨\¨
Let's say you want to copy from /mnt/data1/ to /mnt/data2/
${s} is your string (e.g. $(pwd), i.e. the directory you are in):
$ echo ${s} | sed -e "s#/mnt/data1\(/.*\)#\1#"
This line removes "/mnt/data1" from the string ${s}.
> than copy the ¨\foto\digikam\¨ part
> put at the end of the row ¨¨ O:\and paste
> and add copiedphoto.jpg
> now you have something like
> move ¨d:\foto\digikam\photo.jpg¨ ¨O:\foto\digikam\photo.jpg¨
> and you can apply it to all rows.
For this, you can do (from /mnt/data1/foto/digikam/ to
/mnt/data2/foto/digikam/):
$ for f in $(ls); do move ${f} $(pwd | sed -e "s#/mnt/data1\(/.*\)#\1/#"); done
For most batch jobs (dealing with files), you can use bash script,
either in one line like I wrote, or execute a file like this one
(which is easier to read):
$ cat batch.sh
#!/bin/bash
for f in $(ls)
do
TARGET=$(pwd | sed -e "s#/mnt/data1\(/.*\)#\1/#")
if [ ! -d ${TARGET} ]
then
mkdir -p ${TARGET}
fi
move ${f} ${TARGET}
done
Then (after a "chmod 755 batch.sh" to make it executable), you just
have to do this in the directory where your photos are:
$ ./batch.sh
Note that I added a test to create the directory in the target if it
is missing, and the one line command suppose that
/mnt/data2/foto/digikam already exists.
A better version would replace $(ls) with $(ls *.jpg) in case there
could be directories listed with $(ls).
sed is the key here (along with bash scripting). It stands for Simple
EDitor (simple does not mean easy here...), but it has no graphical
interface, it is always run the same way I did. You'll find it very
convenient if you learn how to use it. Note that some people will use
awk (I think) to do the same job.
I hope that helps.
--
Benjamin Girault.
More information about the Digikam-users
mailing list