![需要帮助 grep 播放列表](https://linux22.com/image/1498588/%E9%9C%80%E8%A6%81%E5%B8%AE%E5%8A%A9%20grep%20%E6%92%AD%E6%94%BE%E5%88%97%E8%A1%A8.png)
我使用来自互联网的播放列表,该列表每天都会更新。我想对 URL 进行排序和 grep。
播放列表很乱,看起来像这样
#EXTINF:-1 tvg-id="ORF1.at" group-title="Deutsch" tvg-logo="0071.png",[COLOR orangered]ORF1 HD[/COLOR] http://62.65.140.214:80/session/a126e0c8-3ffd-11e6-9c3e-005056bc49ac/nvnv5a/1/1010/index.m3u8?token=549d54af4ca436ec0d599cace4ee6bf4_1467513323_1467513323&p=127|X-Forwarded-For=85.195.192.0 #EXTINF:-1 tvg-id="ORF2.at" group-title="Deutsch" tvg-logo="0073.png",[COLOR orangered]ORF2 HD[/COLOR] http://62.65.140.216:80/session/a763552a-3ffd-11e6-9384-005056bc49ac/nvnv5a/1/1011/index.m3u8?token=e3fb5624d5f8458f8e44bc6e429fd75d_1467513324_1467513324&p=127|X-Forwarded-For=85.195.192.0 #EXTINF:0800 tvg-id="ARD.de" group-title="Deutsch" tvg-logo="0001.png",[COLOR orangered]ARD SD[/COLOR] http://daserste_live-lh.akamaihd.net/i/daserste_int@91203/index_2692_av-p.m3u8 #EXTINF:0800 tvg-id="ARD.de" group-title="Deutsch" tvg-logo="0002.png",[COLOR orangered]Das Erste[/COLOR] http://daserste_live-lh.akamaihd.net/i/daserste_de@91204/master.m3u8 #EXTINF:0800 tvg-id="" group-title="Deutsch" tvg-logo="",[COLOR orangered]arte[/COLOR] http://delive.artestras.cshls.lldns.net/artestras/contrib/delive.m3u8
有没有可能把这个乱七八糟的事情整理成这样
#EXTINF:-1 tvg-id="ORF1.at" group-title="Deutsch" tvg-logo="0071.png",[COLOR orangered]ORF1 HD[/COLOR]
http://62.65.140.214:80/session/a126e0c8-3ffd-11e6-9c3e-005056bc49ac/nvnv5a/1/1010/index.m3u8?token=549d54af4ca436ec0d599cace4ee6bf4_1467513323_1467513323&p=127|X-Forwarded-For=85.195.192.0
#EXTINF:-1 tvg-id="ORF2.at" group-title="Deutsch" tvg-logo="0073.png",[COLOR orangered]ORF2 HD[/COLOR]
http://62.65.140.216:80/session/a763552a-3ffd-11e6-9384-005056bc49ac/nvnv5a/1/1011/index.m3u8?token=e3fb5624d5f8458f8e44bc6e429fd75d_1467513324_1467513324&p=127|X-Forwarded-For=85.195.192.0
有人可以帮我排序吗?
我尝试了一些在 Google 上找到的 grep 命令,但由于字符串超出了行,我似乎无法对其进行排序。
答案1
我创建了一个名为的文件,playlist
其中包含您的字符串:
#EXTINF:-1 tvg-id="ORF1.at" group-title="Deutsch" tvg-logo="0071.png",[COLOR orangered]ORF1 HD[/COLOR] http://62.65.140.214:80/session/a126e0c8-3ffd-11e6-9c3e-005056bc49ac/nvnv5a/1/1010/index.m3u8?token=549d54af4ca436ec0d599cace4ee6bf4_1467513323_1467513323&p=127|X-Forwarded-For=85.195.192.0 #EXTINF:-1 tvg-id="ORF2.at" group-title="Deutsch" tvg-logo="0073.png",[COLOR orangered]ORF2 HD[/COLOR] http://62.65.140.216:80/session/a763552a-3ffd-11e6-9384-005056bc49ac/nvnv5a/1/1011/index.m3u8?token=e3fb5624d5f8458f8e44bc6e429fd75d_1467513324_1467513324&p=127|X-Forwarded-For=85.195.192.0 #EXTINF:0800 tvg-id="ARD.de" group-title="Deutsch" tvg-logo="0001.png",[COLOR orangered]ARD SD[/COLOR] http://daserste_live-lh.akamaihd.net/i/daserste_int@91203/index_2692_av-p.m3u8 #EXTINF:0800 tvg-id="ARD.de" group-title="Deutsch" tvg-logo="0002.png",[COLOR orangered]Das Erste[/COLOR] http://daserste_live-lh.akamaihd.net/i/daserste_de@91204/master.m3u8 #EXTINF:0800 tvg-id="" group-title="Deutsch" tvg-logo="",[COLOR orangered]arte[/COLOR] http://delive.artestras.cshls.lldns.net/artestras/contrib/delive.m3u8
然后跑了
sed 's/#EXTINF:/\n#EXTINF:/g' playlist | sort -t ":" -nk2 | sed 's/http:/\nhttp:/g'
这会将每个换行符拆分成多个,#EXTINF
然后根据冒号后的数字进行数字排序,并将相应的 URL 放在下一行。