Abbreviated Journal Names with Mendeley - Replace Long Journal Names Automatically

I created a small bash script that replaces the full journal names with the abbreviated ones (MEDLINE-standard).
You need to download the list of journals from pubmed and place it within the same folder of the script.

Additionally you need sqlite3 (sudo apt-get install sqlite3) under Ubuntu Linux. On Windows systems you need to install cygwin or something similar first i think… but it easier to make the conversion on a linux box on the campus.

Then you should adjust the path to your database file according to your operating system:

  • Windows XP: C:\Documents and Settings\<Your Name>\Local Settings\Application Data\Mendeley Ltd\Mendeley Desktop\
  • Windows Vista / Windows 7: %LOCALAPPDATA%\Mendeley Ltd.\Mendeley Desktop\
  • Mac OS X: /Users/<Your username>/Library/Application Support/Mendeley Desktop/
  • Linux: ~/.local/share/data/Mendeley Ltd./Mendeley Desktop/

After you have done so, I recommend running the script once in echo only mode. If the result looks okay, change the last echo to sqlite3 $db.

Please feel free to leave comments…

Good luck ;)
#!/bin/bash
db=test.sqlite # set the db-file here. The location depends on the OS you use.
limit="WHERE confirmed='true' AND type='JournalArticle'"
sqlite3 $db "SELECT id FROM Documents $limit" > temp_ids.txt
cat temp_ids.txt | while read line
do
long=$(sqlite3 $db "SELECT publication FROM Documents WHERE id=$line")
echo "long = $long"
#echo "The id is $line"
line_pubm=$(grep -i -n -m 1 "$long" J_Medline.txt | cut -f1 -d:)
#echo "linenumber in pubm= $line_pubm"
abbr_linen=$(( $line_pubm + 1 ))
short=$(sed -n ${abbr_linen}p J_Medline.txt | sed 's/MedAbbr: //' | tr -cd '[:alnum:]‘)
echo “short= $short”
LEN=$(echo ${#short})
echo $LEN
if [ "$short" ]; then
echo “UPDATE Documents SET publication=’$short’ WHERE id=$line”
# sqlite3 $db
# make a security update of your sqlite-file and replace the echo from above with sqlite3 $db
else
echo “no or short shortname (<3 chars) - not changed”
fi
done

Tags: , , , , , , ,

3 Responses to “Abbreviated Journal Names with Mendeley - Replace Long Journal Names Automatically”

  1. Martin Says:

    Running this script in my ubuntu 9.10, i constantly get:

    MendeleyScript.sh: 2: Ltd./Mendeley: not found

    However, when I paste the location from your description, i pop right into the Mendeley folder. What am I doing wrong?

  2. Rhodri Cusack Says:

    Thanks for the script, it is very useful!

    On a Mac I had a couple of problems: the quotes have been changed in the HTML to opening and closing quotes, which are different characters that bash doesn\’t recognize. Second, I needed to add \"\" around \"$db\" due to the spaces in the filename on a Mac. The final version that did the job is:

    #!/bin/bash
    db=\"/Users/rcusack/Library/Application Support/Mendeley Desktop/rhodricusack@gmail.com@www.mendeley.com.sqlite\" # set the db-file here. The location depends on the OS you use.
    limit=\"WHERE confirmed=\’true\’ AND type=\’JournalArticle\’\"
    sqlite3 \"$db\" \"SELECT id FROM Documents $limit\" > temp_ids.txt
    cat temp_ids.txt | while read line
    do
    long=$(sqlite3 \"$db\" \"SELECT publication FROM Documents WHERE id=$line\")
    echo \"long = $long\"
    echo \"The id is $line\"
    line_pubm=$(grep -i -n -m 1 \"$long\" J_Medline.txt | cut -f1 -d:)
    echo \"linenumber in pubm= $line_pubm\"
    abbr_linen=$(( $line_pubm + 1 ))
    short=$(sed -n ${abbr_linen}p J_Medline.txt | sed \’s/MedAbbr: //\’ | tr -cd \’[:alnum:]\’)
    echo “short= $short”
    LEN=$(echo ${#short})
    echo $LEN
    if [ \"$short\" ]; then
    echo $short
    echo $line
    sqlite3 \"$db\" \"UPDATE Documents SET publication=\’${short}\’ WHERE id=${line}\"
    # sqlite3 $db
    # make a security update of your sqlite-file and replace the echo from above with sqlite3 $db
    else
    echo \"no or short shortname (<3 chars) - not changed\"
    fi
    done

  3. Rhodri Cusack Says:

    The quotes in the comment above have been escaped. A better version is here:
    http://www.cusacklab.org/?page_id=559

Leave a Reply

Security Code: