ストリームからテキストの特定の行のみを表示およびパイプする
質問
Wordnetを使用した辞書検索用のコマンドラインスクリプトは次のとおりです。
#!/bin/bash
# Command line look up using Wordnet - command line dictionary
echo "Type in your word:"
read word
/usr/bin/curl -s -A 'Mozilla/4.0' 'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&h=' \
| html2text -ascii -nobs -style compact -width 500 | grep "*"
「こんにちは」と入力します出力は次のとおりです。
Type in your word:
hello
**** Noun ****
* S:(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
S:の後にある文字列のみが必要で、その前には何もありません。以下を削除したいです。
**** Noun ****
* S:
パイピング用にこれをそのままにする->
(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
解決 3
DigitalRossの答えに追加するコードが動作しています:
#!/bin/bash
# Command line look up using Wordnet - command line dictionary
echo "Type in your word:"
read word
/usr/bin/curl -s -A 'Mozilla/4.0' 'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&h=' \
| html2text -ascii -nobs -style compact -width 500 | grep "*" | sed 's/^[^S]*S://' | grep -v "\*\*\*\* "
これは、私が信じているすべてのフォーマットを削除します。 ****名詞****
行も削除されます。
他のヒント
sed -e
を変更して s /^.* S:/ /
を実行するか、場合によっては細心の注意を払って s / ^ [^ S] * S://
必要なものが得られます。 sedコマンドがタブを置き換えている場合(わかりません)、それを保持することをお勧めします...
grep" *"
の意図がわかりませんが、次のように変更できます:
grep -Eo '\(.*'
所属していません StackOverflow