0

私はwordnetのオンラインデータベースから読み取るbashスクリプトを実装しようとしていて、1つのコマンドでさまざまなテキストファイルを削除する方法があるかどうか疑問に思っていました。

FileDumpの例:

**** Noun ****
(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
**** Verb ****
(v)run (move fast by using one's feet, with one foot off the ground at any given time) "Don't run--you'll be out of breath"; "The children ran to the store"
**** Adjective ****
(adj)running ((of fluids) moving or issuing in a stream) "as mountain stream with freely running water"; "hovels without running water"

文法の側面を説明する行を削除する必要があります。

**** Noun ****
**** Verb ****
**** Adjective ****

単語の定義のみを含むクリーンなファイルを作成するために、次のようにします。

(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
(v)run (move fast by using one's feet, with one foot off the ground at any given time) "Don't run--you'll be out of breath"; "The children ran to the store"
(adj)running ((of fluids) moving or issuing in a stream) "as mountain stream with freely running water"; "hovels without running water"

文法用語の周りの*記号は、sedで私をつまずかせています。

4

4 に答える 4

4

それらの行の内容だけに基づいてファイルから行全体を選択したい場合grepは、おそらく利用可能な最も適切なツールです。ただし、星などの一部の文字には特別な意味がgrepあるため、円記号で「エスケープ」する必要があります。これにより、4つの星とスペースで始まる行だけが印刷されます。

grep "^\*\*\*\* " textfile

ただし、それに一致しない行を保持する必要があるため、パターンに一致しない行を印刷するという-vオプションが必要です。grep

grep -v "\*\*\*\* " textfile

それはあなたが望むものを与えるはずです。

于 2009-10-24T10:15:15.343 に答える
2
sed '/^\*\{4\} .* \*\{4\}$/d'

または少し緩い

sed '/^*\{4\}/d'
于 2009-10-24T10:27:22.373 に答える
1
 sed 's/^*.*//g' test | grep .
于 2009-10-24T10:22:14.657 に答える
0
# awk '!/^\*\*+/' file
(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
(v)run (move fast by using one's feet, with one foot off the ground at any given time) "Don't run--you'll be out of breath"; "The children ran to the store"
(adj)running ((of fluids) moving or issuing in a stream) "as mountain stream with freely running water"; "hovels without running water"
于 2009-10-24T12:21:09.863 に答える