Text-Processing

如何將一行包含特定單詞的文本導出到另一個文本文件?

  • July 26, 2021

我有一個很大的文本列表,為了更容易排序,我希望能夠將具有某些單詞的行導出到另一個文本文件。

下面是一個文本範例:

- JOCKEY: D Tudhope riding Dynamic Force in the 1.45 at Ayr
- TRAINER: A W Carroll training Be Fair in the 1.55 at Lingfield Park
- TRAINER: M L W Bell training The Vegas Raider in the 1.55 at Lingfield Park
- JOCKEY: Oisin Murphy riding The Vegas Raider in the 1.55 at Lingfield Park
- JOCKEY: W Buick riding Crestwood in the 1.55 at Lingfield Park
- TRAINER: P F Nicholls training Chez Hans in the 2.05 at Newton Abbot
- JOCKEY: Callum Rodriguez riding Gigiʼs Beach in the 2.15 at Ayr

如何僅將顯示“Lingfield Park”的行導出到另一個文本文件?

我希望這是有道理的。

一個簡單的grep+ 重定向:

$ grep '\bLingfield Park\b' FILE > ANOTHER_FILE
$ cat ANOTHER_FILE
- TRAINER: A W Carroll training Be Fair in the 1.55 at Lingfield Park
- TRAINER: M L W Bell training The Vegas Raider in the 1.55 at Lingfield Park
- JOCKEY: Oisin Murphy riding The Vegas Raider in the 1.55 at Lingfield Park
- JOCKEY: W Buick riding Crestwood in the 1.55 at Lingfield Park

引用自:https://unix.stackexchange.com/questions/659893