我有一个名为 test 的文件,其中包含以下几行:
1. Lil Nas X Ft, Billy Ray Cyrus - Old Town Road (Remix).mp3
10. Mark Ronson - Find U Again (feat. Camila Cabello).mp3
11. Mabel - Mad Love.mp3
12. Sigala & Becky Hill - Wish You Well.mp3
13. CamelPhat & Jake Bugg - Be Someone.mp3
14. Jess Glynne & Jax Jones - One Touch.mp3
15. Zara Larsson - Don't Worry Bout Me.mp3
16. Pink Ft, Cash Cash - Can We Pretend.mp3
17. Jax Jones & Martin Solveig & Madison Beer - All Day And Night (Jax Jones & Martin Solveig Present Europa).mp3
18. Martin Garrix - Summer Days (feat. Macklemore & Patrick Stump of Fall Out Boy).mp3
19. Little Mix - Bounce Back.mp3
我想要使用 1. 代表歌曲名称的第一列的 grep。我正在使用的命令是:
#cat test | grep -w "1."
1. Lil Nas X Ft, Billy Ray Cyrus - Old Town Road (Remix).mp3
10. Mark Ronson - Find U Again (feat. Camila Cabello).mp3
11. Mabel - Mad Love.mp3
12. Sigala & Becky Hill - Wish You Well.mp3
13. CamelPhat & Jake Bugg - Be Someone.mp3
14. Jess Glynne & Jax Jones - One Touch.mp3
15. Zara Larsson - Don't Worry Bout Me.mp3
16. Pink Ft, Cash Cash - Can We Pretend.mp3
17. Jax Jones & Martin Solveig & Madison Beer - All Day And Night (Jax Jones & Martin Solveig Present Europa).mp3
18. Martin Garrix - Summer Days (feat. Macklemore & Patrick Stump of Fall Out Boy).mp3
19. Little Mix - Bounce Back.mp3
一切似乎都被抓住了。但我想只看到以下内容:
1. Lil Nas X Ft, Billy Ray Cyrus - Old Town Road (Remix).mp3
即使作为固定字符串,
1.
也会匹配11.
. 但它不是字符串,而是正则表达式,因此某些字符应用规则而不是匹配文字。点是“任何字符”的替代;要匹配文字点,您需要将其转义为
\.
. 您还可以为行首添加一个标记(插入符号,^
),以便1.
仅在行首匹配。您也可以丢弃
cat
因为grep
(和许多其他命令)直接接受文件名。然后你会得到这样的东西
在您的数据集中,它只匹配一行