ฉันกำลังดึง URL จากเว็บไซต์โดยใช้ cURL ดังต่อไปนี้
curl www.somesite.com | grep "<a href=.*title=" > new.txt
ไฟล์ new.txt ของฉันมีดังต่อไปนี้
<a href="http://website1.com" title="something">
<a href="http://website1.com" information="something" title="something">
<a href="http://website2.com" title="some_other_thing">
<a href="http://website2.com" information="something" title="something">
<a href="http://websitenotneeded.com" title="something NOTNEEDED">
อย่างไรก็ตามฉันต้องดึงข้อมูลด้านล่างเท่านั้น
<a href="http://website1.com" title="something">
<a href="http://website2.com" information="something" title="something">
ฉันพยายามที่จะไม่สนใจ<a href
ที่มีข้อมูลในพวกเขาและท้ายที่สุดกับชื่อNOTNEEDED
ฉันจะแก้ไขคำสั่ง grep ได้อย่างไร
ผลลัพธ์ที่คุณแสดงที่นี่ถูกต้องหรือไม่ ข้อความที่อธิบายไม่สมเหตุสมผลตามตัวอย่างนี้
—
slm
คุณไม่ต้องการ
—
terdon
curl www.somesite.com | grep "<a href=.*title=" | grep -v NOTNEEDED > new.txt
หรือ
@terdon นั่นคือสิ่งที่ฉันกำลังมองหา ฉันยอมรับได้ว่าเป็นคำตอบถ้าคุณโพสต์ไว้
—
Ramesh
Ramesh เป็นคำตอบโดยพื้นฐานของ @ slm ฉันเพิ่งแก้ไขเพื่อให้คุณสามารถยอมรับได้
—
terdon
โอ้ใช่ฉันไม่ได้ตระหนักถึงท่อที่มีประสิทธิภาพนี้ ฉันยอมรับมันเป็นคำตอบ ขอบคุณ!
—
Ramesh