View Single Post
Old 11-11-2013, 01:01 PM   #6
Gozer404
Member
Gozer404 began at the beginning.
 
Gozer404's Avatar
 
Posts: 21
Karma: 10
Join Date: Oct 2013
Location: France
Device: SONY PRS-T2
Fine thanks. Based on this I created a bash script for cygwin:
I did'nt debug all error cases, in particular some grep results are not correctly filtered


Code:
#!/bin/bash

# Create book.txt from sony reader database: sqlite3.exe books.db 'select author,title,added_date from books' > book.txt
# Create reference calibre.txt from calibre database: sqlite3.exe  metadata.db 'select author_sort,title,timestamp from books' > calibre.txt
#
#

N=0
cat book.txt | while read LINE ; do
        N=$((N+1))
        echo "Line $N = $LINE"
        FOUND=""
        BTITLE=`echo "$LINE" | awk -F'|' '{print $2}'`
        BDAT=`echo "$LINE" | awk -F'|' '{print $3}'`
        # Search title in calibre file
        FOUND=`grep "$BTITLE" calibre.txt`
        if [ $? -eq 0 ]
        then
                # Create date based on calibre date
                CDAT1=`echo "$FOUND" | awk -F'|' '{print $3}'`
                CTITLE=`echo "$FOUND" | awk -F'|' '{print $2}'`
                CDAT2=`date --date="$CDAT1" +"%s"`
                CDAT="${CDAT2}000"
                if [ x"${BDAT}" != x"${CDAT}" ]
                then
                        echo "Line $N = Change \"$BTITLE\" status date to ${CDAT}"
                        # Update sony datebase with this date
                        sqlite3 books.db "update books set added_date=$CDAT where title=\"$CTITLE\";"
                fi
        fi
done
Gozer404 is offline   Reply With Quote