سؤال

فيما يلي برنامج نصي لسطر الأوامر لإجراء عملية بحث عن القاموس باستخدام 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 "\*\*\*\* "

إنه يزيل كل التنسيق الذي أعتقده. يزيل **** Noun **** الخطوط كذلك.

نصائح أخرى

أعتقد أنه إذا غيرت ذلك sed -e لكى يفعل s/^.*S:/ / أو ربما ، أن تكون حذرا للغاية ، s/^[^S]*S:// سوف تحصل على ما تريد. إذا كان الأمر SED يستبدل علامة تبويب (لا أستطيع أن أقول) ، فقد ترغب في الحفاظ على ذلك ...

لا أعرف ماذا grep "*" المقصود القيام به ، ولكن يمكنك تغييره إلى:

grep -Eo '\(.*'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top