I'd like to know if it's possible to send matching files from Recoll (searches words or strings in the content of several files .pdf .doc, etc) into a folder.
Thanks!
I'd like to know if it's possible to send matching files from Recoll (searches words or strings in the content of several files .pdf .doc, etc) into a folder.
Thanks!
You can use the command-line search:
recoll -t "yourquery"
and then filter it to have a list of filenames. For example (surely you can do that more neatly and safely):
[:~/tmp/lalla/out] % files=$(recoll -t "x11vnc" | awk '{print $2}' | grep file:/// | sed 's+\[file://++' | sed 's/]$//')
[:~/tmp/lalla/out] % echo $files
/home/romano/personal/archivio/Tricks/remote-ubuntu-login.txt
/home/romano/lib/Jed_Backups/remote-ubuntu-login.txt
/home/romano/software/documentation/Ubuntu:Maverick.html
/home/romano/personal/library/Unknown/Ubuntu_Maverick
/home/romano/.wajig/romano-asus/Available.prv
/home/romano/.wajig/romano-asus/Available
/home/romano/.wajig/asus-romano/Available.prv
/home/romano/.wajig/asus-romano/Available
and then using them:
cp $files my-new-dir/
To understand the complex pipe, recoll -t outputs something like:
8 results
text/plain [file:///home/romano/personal/archivio/Tricks/remote-ubuntu-login.txt] [remote-ubuntu-login.txt] 322 bytes
awk prints just the second (space-separated) items (and will mess things up if there are spaces in file names, I suppose); grep selects only lines with "file:///" in it sed remove the leading [file:// (note the use of + as separator) sed strips the trailing ] Probably the correct way would be to write a little python program using the recoll python bindings.
Bash script solution
@Rmano beat me to it but I guess it's always good to have different solutions. Here's the script I composed:
#!/bin/bash
# NAME: recoll_move_results
# VERSION: 0.1
# AUTHOR: (c) 2014 Glutanimate
# DESCRIPTION: queries recoll database for provided string and either symlinks or moves
# results
# DEPENDENCIES: recoll
#
# LICENSE: GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
#
# NOTICE: THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
# EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
# IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
# PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
# YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
#
# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
# COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
# PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
# INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
# THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
# INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
# PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
# PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
# USAGE: recoll_move_results <query>
# VARIABLES / SETINGS
DESTINATION="$HOME/recollresults" # ⇐ Set the destination folder here
QUERY="$@"
USAGE="$0 <query>"
if [[ -z "$QUERY" ]]
then
echo "Error: No arguments provided."
echo "Usage: $USAGE"
exit 1
fi
# create destination folder
mkdir -p "$DESTINATION"
# FUNCTIONS
# query recoll and convert URIs to file paths
recoll_get_results(){
recoll -t -b "$QUERY" 2> /dev/null | sed 's,file://,,g'
}
# symlink or move files read from stdin
move_files(){
while read -r FILE; do
echo "Processing $FILE"
FILENAME="${FILE##*/}"
# PLEASE USE ONLY ONE OF THE OPTIONS BELOW. COMMENT THE ONE YOU DON'T WANT
# AND UNCOMMENT THE ONE YOU DO WANT
ln -sv "$FILE" "$DESTINATION/$FILENAME" # Create a symbolic link in $DESTINATION
#mv -v "$FILE" "$DESTINATION/$FILENAME" # Move to $DESTINATION
done
}
# MAIN
recoll_get_results "$QUERY" | move_files
Usage
Use the script with:
recoll_move_results <query>
It will perform the provided query and either symlink or move all search results to a newly created folder. Spaces and special characters (aside from newlines) should be handled correctly by the script.
Settings
Here are a few settings you can customize:
DESTINATION="$HOME/recollresults" - modify this to set the destination folderln -sv "$FILE" "$DESTINATION/$FILENAME" - comment this line (with #) and uncomment the following one if you are sure you want to move the files instead of creating symbolic links to themPlease note that moving the results will make it impossible to access the files from Recoll's search interface until you update the index again.
Another option would be to copy the files by replacing:
`ln -sv "$FILE" "$DESTINATION/$FILENAME"`
with
`cp -v "$FILE" "$DESTINATION/$FILENAME"`