باستخدام جوجل كما عبر باش على بحث القاموس، كيف يمكن للمرء أن الاستيلاء على التعريف الأول؟

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

سؤال

#!/bin/bash
# Command line look up using Google's define feature - command line dictionary

echo "Type in your word:"
read word

/usr/bin/curl -s -A 'Mozilla/4.0'  'http://www.google.com/search?q=define%3A+'$word \
| html2text -ascii -nobs -style compact -width 500 | grep "*"

ومقالب سلسلة كاملة من التعريفات من google.com مثال هو التالي:

Type in your word:
world
    * universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"
    * people in general; especially a distinctive group of people with some shared interest; "the Western world"
    * all of your experiences that determine how things appear to you; "his world was shattered"; "we live in different worlds"; "for them demons were as much a part of reality as trees were"

والشيء هو، أنا لا أريد كل التعاريف، فقط أول واحد:

universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"

وكيف يمكن لانتزاع هذه الجملة الخروج من الإخراج؟ ما بين اثنين *، يمكن أن تستخدم؟

هل كانت مفيدة؟

المحلول

وهذا سترفع الرصاصة من بداية السطر الأول، طباعته والتخلص من بقية الإخراج.

sed 's/^ *\* *//; q'

نصائح أخرى

وإضافة هذه:

head -n 1 -q | tail -n 1

وهكذا يصبح:

#!/bin/bash
# Command line look up using Google's define feature - command line dictionary

echo "Type in your word:"
read word

/usr/bin/curl -s -A 'Mozilla/4.0'  'http://www.google.com/search?q=define%3A+'$word \
| html2text -ascii -nobs -style compact -width 500 | grep "*" | head -n 1 -q | tail -n 1

ومحاولة قيادة رئيس

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top