سؤال

ولقد تم محاولة تنفيذ السيناريو باش الذي يقرأ من قاعدة بيانات وردنت على الانترنت وتم أتساءل عما اذا كان هناك طريقة لإزالة ملفات نصية متنوعة مع أمر واحد.

مثال 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"

والرموز * حول شروط النحوية يبذلون قصارى جهدهم لي في الحوار الاقتصادي الاستراتيجي.

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

المحلول

إذا كنت تريد تحديد خطوط كاملة من ملف تستند فقط على محتوى تلك الخطوط، grep ربما هو الأداة الأكثر مناسبة المتاحة. ومع ذلك، فإن بعض الشخصيات، مثل النجوم الخاصة بك، لها معان خاصة إلى grep، لذلك يجب أن تكون "هرب" بخط مائل. وهذا طباعة مجرد خطوط بدءا من النجوم الأربعة والفضاء:

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

ولكن، وتريد للحفاظ على الخطوط التي <م> لا المباراة التي، لذلك كنت في حاجة إلى الخيار -v لgrep الذي يفعل ذلك بالضبط: يطبع الخطوط التي <م> لا تتطابق مع النمط.

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

وهذا يجب أن تعطيك ما تريد.

نصائح أخرى

sed '/^\*\{4\} .* \*\{4\}$/d'

وأو اكثر مرونة قليلا

sed '/^*\{4\}/d'
 sed 's/^*.*//g' test | grep .
# 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"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top