如何将具有特定单词的文本行导出到另一个文本文件?

如何将具有特定单词的文本行导出到另一个文本文件?

我有一个很大的文本列表,为了更容易排序,我希望能够将包含某些单词的行导出到另一个文本文件。

以下是文本示例:

- 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”行导出到另一个文本文件?

我希望这是有道理的。

答案1

一个简单的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

相关内容