我有一个很大的文本列表,为了更容易排序,我希望能够将包含某些单词的行导出到另一个文本文件。
下面是一个文本示例:
- 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
Run Code Online (Sandbox Code Playgroud)
如何仅将显示“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
Run Code Online (Sandbox Code Playgroud)