置き換えるXMLタグからの輸出Referencer.reflibにbibtex形式ファイル名をそのままURLエンコーディングを除去し、bashコマンド

StackOverflow https://stackoverflow.com/questions/2105385

質問

が多いのですが、まだ参照Referencer.監督-選手コメなどのファイル名にマbibtexファイルの輸出時におけるReferencer.からのソフトウェアがないことによりデフォルトのようにしている利用sedコマンドのファイル名としてbibtex情報のXMLファイル以前の輸出は、このようにファイル名を指定します。

入力

  <doc>
<filename>file:///home/dwickrama/Desktop/stevenJonesLab/papers/Transcription%20Factor%20Binding/A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</filename>
<relative_filename>A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</relative_filename>
<key>Sadowski93</key>
<notes></notes>
<bib_type>article</bib_type>
<bib_doi></bib_doi>
<bib_title>A common nuclear signal transduction pathway activated by growth factor and cytokine receptors.</bib_title>
<bib_authors>Sadowski, H B and Shuai, K and Darnell, J E and Gilman, M Z</bib_authors>
<bib_journal>Science</bib_journal>
<bib_volume>261</bib_volume>
<bib_number>5129</bib_number>
<bib_pages>1739-44</bib_pages>
<bib_year>1993</bib_year>
<bib_extra key="pmid">8397445</bib_extra>

出力

  <doc>
<filename>file:///home/dwickrama/Desktop/stevenJonesLab/papers/Transcription%20Factor%20Binding/A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</filename>
<bib_extra key="File">article:../Transcription\ Factor\ Binding/A\ Common\ Nuclear\ Signal\ Transduction\ Pathway\ Activated\ by\ Growth\ Factor\ and\ Cytokine.pdf:pdf</bib_extra>
<relative_filename>A%20Common%20Nuclear%20Signal%20Transduction%20Pathway%20Activated%20by%20Growth%20Factor%20and%20Cytokine.pdf</relative_filename>
<key>Sadowski93</key>
<notes></notes>
<bib_type>article</bib_type>
<bib_doi></bib_doi>
<bib_title>A common nuclear signal transduction pathway activated by growth factor and cytokine receptors.</bib_title>
<bib_authors>Sadowski, H B and Shuai, K and Darnell, J E and Gilman, M Z</bib_authors>
<bib_journal>Science</bib_journal>
<bib_volume>261</bib_volume>
<bib_number>5129</bib_number>
<bib_pages>1739-44</bib_pages>
<bib_year>1993</bib_year>
<bib_extra key="pmid">8397445</bib_extra>

使用できます以下のsedコマンドを部分的にいいものの、URLエンコーディングは"%20"には残ります。どのようになるだけで、bibtexタグ?

sed -e 's/\(\ \ \ \ <filename>file:\/\/\/home\/dwickrama\/Desktop\/stevenJonesLab\/papers\)\([^.]*\)\(\.\?\)\(.*\)\(<\/filename>\)/\1\2\3\4\5\n\ \ \ \ <bib_extra\ key=\"File\">article:\.\.\2\3\4:\4<\/bib_extra>/g' NewPapers.reflib > NewPapers.new.reflib
役に立ちましたか?

解決

正規表現とsedのは、XMLを処理するための非常に良いツールではありません、またはURLデコードます。

より完全なスクリプト言語での迅速なスクリプトがより明確にし、確実にそれを行うことができるだろう。 Pythonで次に例を示します。

import urllib, urlparse
from xml.dom import minidom

doc= minidom.parse('NewPapers.reflib')
el= doc.getElementsByTagName('filename')[0]
path= urlparse.urlparse(el.firstChild.data)[2]
foldername, filename= map(urllib.unquote, path.split('/')[-2:])

extra= doc.createElement('bib_extra')
extra.setAttribute('key', 'File')
extra.appendChild(document.createTextNode('article:../%s/%s:pdf' % (foldername, filename)))
el.parentNode.insertBefore(extra, el.nextSibling)
doc.writexml(open('NewPapers.new.reflib'))
(私はそれが正確にどのような形式であること明確ではないとして与えられた出力例では、バックスラッシュエスケープを再現する機能が含まれていない。最も簡単な方法は、filename= filename.replace(' ', '\\ ')だろうが、私は確かにそれは正しいだろうではありませんよ。 )

他のヒント

あなたが必要とするすべては、直後の行を追加することです? ISは、検索後にそうちょうどそれをプリントアウトします。

#!/bin/bash

s='<bib_extra key="File">article:../Transcription\\ Factor\\ Binding/A\\ Common\\ Nuclear\\ Signal\\ Transduction\\ Pathway\\ Activated\\ by\\ Growth\\ Factor\\ and\\ Cytokine.pdf:pdf</bib_extra>'

awk -vstr="$s" '
/<filename>/{
    print
    print str;next
}
{print}' file
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top