@Joseph R. คำตอบที่ยอมรับได้ของประวัตินั้นดี แต่มาดูกันว่ามันจะถูกใช้อย่างไร
ptxสร้างดัชนีคำที่อนุญาต ("ptx") จากข้อความ ตัวอย่างเข้าใจง่ายที่สุด:
$ cat input
a
b
c
$ ptx -A -w 25 input
:1: a b c
:2: a b c
:3: a b c
^^^^ ^ ^^^^-words to the input's right
| +-here is the actual input
+-words to the input's left
ด้านขวาคุณจะเห็นคำที่แตกต่างจากอินพุตและบริบทคำซ้ายและขวาที่ล้อมรอบคำเหล่านั้น คำแรกคือ "a" มันเกิดขึ้นในบรรทัดที่หนึ่งและตามด้วย "b" และ "c" ทางด้านขวา คำที่สองคือ "b" ซึ่งเกิดขึ้นในบรรทัดที่สองโดยมี "a" ทางด้านซ้ายและ "c" ทางด้านขวา ในที่สุด "c" เกิดขึ้นในบรรทัดที่สามและดำเนินการโดย "a" และ "b"
เมื่อใช้สิ่งนี้คุณสามารถค้นหาหมายเลขบรรทัดและคำที่อยู่รอบ ๆ คำใด ๆ ในข้อความ ฟังดูเยอะมากgrepใช่มั้ย ความแตกต่างคือptxเข้าใจโครงสร้างของข้อความในหน่วยทางตรรกะของคำและประโยค สิ่งนี้ทำให้ผลลัพธ์เชิงบริบทptxมีความเกี่ยวข้องมากขึ้นเมื่อจัดการกับข้อความภาษาอังกฤษมากกว่า grep
ลองเปรียบเทียบptxและgrepใช้ย่อหน้าแรกของแท็บลอยด์อเมริกันของ James Ellroy :
$ cat text
America was never innocent. We popped our cherry on the boat over and looked back with no regrets. You can’t ascribe our fall from grace to any single event or set of circumstances. You can’t lose what you lacked at conception.
นี่คือgrep(ด้วยการจับคู่สีเปลี่ยนด้วยตนเองเพื่อล้อมรอบด้วย//):
$ grep -ni you text
1:America was never innocent. We popped our cherry on the boat over and looked back with no regrets. /You/ can’t ascribe our fall from grace to any single event or set of circumstances. /You/ can’t lose what /you/ lacked at conception.
ที่นี่ptx:
$ ptx -Afo <(echo you) text
text:1: /back with no regrets. You can’t ascribe our fall/
text:1: /or set of circumstances. You can’t lose what you/
text:1: /. You can’t lose what you lacked at conception.
เพราะgrepเป็นสายที่มุ่งเน้นและวรรคนี้เป็นหนึ่งในสายการส่งออกไม่ได้ค่อนข้างเป็นที่รัดกุมหรือที่เป็นประโยชน์เป็นผลผลิตจากgrepptx