提问人:john Wallace 提问时间:7/30/2018 最后编辑:john Wallace 更新时间:8/3/2018 访问量:191
使用 sed 一次对 2 行进行排序
Sorting 2 lines at a time with sed
问:
我想用它来对大型播放列表文件进行排序。每个播放列表项都有 2 行,因此我需要根据第一行之后的字符串进行排序(因此在本例中,第一行将是 UK:Button 1(SG)),对第一行和下一行进行排序(以 开头的行)。sed
tvg-name=
http
我见过非常相似的正则表达式示例,但语法超出了我的范围,无法进行逆向工程以适应我的文件。谁能帮忙?
#EXTM3U
#EXTINF:-1 tvg-id="BBCRedButton.uk" tvg-name="UK: BBC Red Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC Red Button 1 (SG)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/112233.ts
#EXTINF:-1 tvg-id="BBC1London.uk" tvg-name="UK: BBC ONE (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC ONE (HD) (720p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/36011.ts
#EXTINF:-1 tvg-id="BBC1Scotland.uk" tvg-name="UK: BBC One Scot FHD (1080p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC One Scot FHD (1080p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/24651.ts
#EXTINF:-1 tvg-id="" tvg-name="Act Of Grace" tvg-logo="http://wesite.test:8080/images/skQxxCIxEWuXL4tmPcfDoFjtSZU_small.jpg" group-title="_Movies_",Act Of Grace
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102408.mp4
#EXTINF:-1 tvg-id="" tvg-name="Act Of Valor" tvg-logo="http://wesite.test:8080/images/1Xcd5ci69pVXMPP02DU11Ffq0yY_small.jpg" group-title="_Movies_",Act Of Valor
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96873.mp4
#EXTINF:-1 tvg-id="" tvg-name="Action Jackson" tvg-logo="http://wesite.test:8080/images/rg5WY1SiyPDuTYZs2vgTV0csVbz_small.jpg" group-title="_Movies_",Action Jackson
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96874.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Vengeance" tvg-logo="http://wesite.test:8080/images/r5o6vWPYOQs6bv91gQ8kQs2zQYl_small.jpg" group-title="_Movies_",Acts Of Vengeance
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/107101.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creed" tvg-logo="http://wesite.test:8080/images/hKzhV274pkZBSpXfCjUyzbyYKLl_small.jpg" group-title="Drama",Creed
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102773.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creep Van" tvg-logo="http://wesite.test:8080/images/r2tSTcns0gHVynnLVPwCtTePfOt_small.jpg" group-title="Horror",Creep Van
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/105306.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creepozoids" tvg-logo="http://wesite.test:8080/images/gZ3HBNBYe6hDTsocsXjDYGv0ZXD_small.jpg" group-title="",Creepozoids
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/106831.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creepshow 2" tvg-logo="http://wesite.test:8080/images/qxJWtBb89RaSRgLuz1d6ZuFTfVG_small.jpg" group-title="Horror",Creepshow 2
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/105307.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Violence" tvg-logo="http://wesite.test:8080/images/pK9CugRd3DIP0THBH8WlGrvk5vy_small.jpg" group-title="_Movies_",Acts Of Violence
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96711.mp4
#EXTINF:-1 tvg-id="" tvg-name="Adaptation" tvg-logo="http://wesite.test:8080/images/5trb1V5f3IsjpZx2GiuUylowl3W_small.jpg" group-title="_Movies_",Adaptation
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/99509.mp4
预期输出 :
#EXTM3U
#EXTINF:-1 tvg-id="BBCRedButton.uk" tvg-name="UK: BBC Red Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC Red Button 1 (SG)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/112233.ts
#EXTINF:-1 tvg-id="BBC1London.uk" tvg-name="UK: BBC ONE (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC ONE (HD) (720p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/36011.ts
#EXTINF:-1 tvg-id="BBC1Scotland.uk" tvg-name="UK: BBC One Scot FHD (1080p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC One Scot FHD (1080p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/24651.ts
#EXTINF:-1 tvg-id="" tvg-name="Act Of Grace" tvg-logo="http://wesite.test:8080/images/skQxxCIxEWuXL4tmPcfDoFjtSZU_small.jpg" group-title="_Movies_",Act Of Grace
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102408.mp4
#EXTINF:-1 tvg-id="" tvg-name="Act Of Valor" tvg-logo="http://wesite.test:8080/images/1Xcd5ci69pVXMPP02DU11Ffq0yY_small.jpg" group-title="_Movies_",Act Of Valor
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96873.mp4
#EXTINF:-1 tvg-id="" tvg-name="Action Jackson" tvg-logo="http://wesite.test:8080/images/rg5WY1SiyPDuTYZs2vgTV0csVbz_small.jpg" group-title="_Movies_",Action Jackson
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96874.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Vengeance" tvg-logo="http://wesite.test:8080/images/r5o6vWPYOQs6bv91gQ8kQs2zQYl_small.jpg" group-title="_Movies_",Acts Of Vengeance
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/107101.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Violence" tvg-logo="http://wesite.test:8080/images/pK9CugRd3DIP0THBH8WlGrvk5vy_small.jpg" group-title="_Movies_",Acts Of Violence
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96711.mp4
#EXTINF:-1 tvg-id="" tvg-name="Adaptation" tvg-logo="http://wesite.test:8080/images/5trb1V5f3IsjpZx2GiuUylowl3W_small.jpg" group-title="_Movies_",Adaptation
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/99509.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creed" tvg-logo="http://wesite.test:8080/images/hKzhV274pkZBSpXfCjUyzbyYKLl_small.jpg" group-title="Drama",Creed
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102773.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creep Van" tvg-logo="http://wesite.test:8080/images/r2tSTcns0gHVynnLVPwCtTePfOt_small.jpg" group-title="Horror",Creep Van
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/105306.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creepozoids" tvg-logo="http://wesite.test:8080/images/gZ3HBNBYe6hDTsocsXjDYGv0ZXD_small.jpg" group-title="",Creepozoids
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/106831.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creepshow 2" tvg-logo="http://wesite.test:8080/images/qxJWtBb89RaSRgLuz1d6ZuFTfVG_small.jpg" group-title="Horror",Creepshow 2
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/105307.mp4
我从我的母版那里复制并粘贴了一部分电影,但两个脚本都没有对输出进行更改。示例如下:
输入:
#EXTINF:-1 tvg-id="" tvg-name="The Santa Clause" tvg-logo="http://liquidit.info:8080/images/hrZjAYAF1o37k4Qb442c4yxwVLw_small.jpg" group-title=_Movies_",The Santa Clause
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/104987.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Santa Clause 2" tvg-logo="http://liquidit.info:8080/images/i7tbiDPIaa4VsQh1wWmbkY4zTRX_small.jpg" group-title=_Movies_",The Santa Clause 2
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/104988.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Santa Clause 3 The Escape Clause" tvg-logo="http://liquidit.info:8080/images/kvKXyrc3cUGqXin2u76Ef8lApMI_small.jpg" group-title=_Movies_",The Santa Clause 3 The Escape Clause
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/101023.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Sapphires" tvg-logo="http://liquidit.info:8080/images/h7zn7Sf0Jl6mFZjGj4TCHjSJj6T_small.jpg" group-title=_Movies_",The Sapphires
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/101024.mp4
#EXTINF:-1 tvg-id="" tvg-name="Fracture" tvg-logo="http://liquidit.info:8080/images/sl5QYze20MclzDLxLDqe3sEJdiW_small.jpg" group-title=_Movies_",Fracture
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/107279.mp4
预期的 Ouptut 将是顶部的电影项目“骨折”,因为 alpabeticalized 排序。
#EXTINF:-1 tvg-id="" tvg-name="Fracture" tvg-logo="http://liquidit.info:8080/images/sl5QYze20MclzDLxLDqe3sEJdiW_small.jpg" group-title=_Movies_",Fracture
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/107279.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Santa Clause" tvg-logo="http://liquidit.info:8080/images/hrZjAYAF1o37k4Qb442c4yxwVLw_small.jpg" group-title=_Movies_",The Santa Clause
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/104987.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Santa Clause 2" tvg-logo="http://liquidit.info:8080/images/i7tbiDPIaa4VsQh1wWmbkY4zTRX_small.jpg" group-title=_Movies_",The Santa Clause 2
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/104988.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Santa Clause 3 The Escape Clause" tvg-logo="http://liquidit.info:8080/images/kvKXyrc3cUGqXin2u76Ef8lApMI_small.jpg" group-title=_Movies_",The Santa Clause 3 The Escape Clause
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/101023.mp4
#EXTINF:-1 tvg-id="" tvg-name="The Sapphires" tvg-logo="http://liquidit.info:8080/images/h7zn7Sf0Jl6mFZjGj4TCHjSJj6T_small.jpg" group-title=_Movies_",The Sapphires
http://liquidit.info:8080/movie/Wallace47B/2IhPHmO9Q8/101024.mp4
答:
如果你想用像 sed 这样的工具来做到这一点,你必须 A) 相信你的字段不包含任何恶性的东西,或者 B) 编写极其艰苦的脚本。tvg-id="http://...
我会尝试一些粗糙但有效的东西,比如这样。首先,将两行合并为一行:
sed 'N;s/\n//'
然后将该字段复制到该行的前面:tvg-name
sed 's/\(.*tvg-name=\)\("[^"]*"\)/\2\1\2/'
然后排序:
sort
然后删除我添加的字段:
sed 's/^"[^"]*"//'
然后将一行分成两行:
sed 'h;s/http.*//;p;g;s/.*http/http/'
把它们放在一起:
sed 'N;s/\n//;s/\(.*tvg-name=\)\("[^"]*"\)/\2\1\2/' filename | sort | sed 's/^"[^"]*"//;h;s/http.*//;p;g;s/.*http/http/'
这可能对你有用(GNU sed & sort):
sed 'N;s/^\(.*\)\n/\1\1/;2h;2!H;$!d;x;s/.*/echo '\''&'\'' | sort -k3,3/e;s/^\(.*\)\1/\1\n/Mg' file
通过复制第一行并删除第一行和第二行之间的换行符,将每两行记录转换为单行。将整个文件收集到保留空间中保存的内存中。在文件末尾,交换到保留空间,并使用 GNU sed 的 evaluate 命令作为替换命令中的标志,对单行记录中第三个字段的文件进行排序。将单行记录重新格式化为两行记录并打印结果。
评论
如果没有更好的样本输入和预期的输出,这只是一个猜测,但这可能是您正在尝试执行的操作:
$ awk -F'"' -v OFS='\t' 'NF>1{key=$4; cnt=0} {print key, ++cnt, $0}' file | sort -t$'\t' -k1,1 -k2,2n -s | cut -f3-
#EXTINF:-1 tvg-id="Button.uk" tvg-name="UK: Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: Button 1 (SG)
#http://website.info:8080/live/xxxxxxxx/xxxxxxxx/112233.ts
##EXTINF:-1 tvg-id="London.uk" tvg-name="UK: London (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: London (HD) (720p)
#http://website.info:8080/live/xxxxxxxx/xxxxxxxx/36011.ts
或者,如果您希望它以相反的方式排序:
$ awk -F'"' -v OFS='\t' 'NF>1{key=$4; cnt=0} {print key, ++cnt, $0}' file | sort -t$'\t' -k1,1r -k2,2n -s | cut -f3-
##EXTINF:-1 tvg-id="London.uk" tvg-name="UK: London (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: London (HD) (720p)
#http://website.info:8080/live/xxxxxxxx/xxxxxxxx/36011.ts
#EXTINF:-1 tvg-id="Button.uk" tvg-name="UK: Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: Button 1 (SG)
#http://website.info:8080/live/xxxxxxxx/xxxxxxxx/112233.ts
它只是在每一行前面加上引号之间的键值,然后是从该值开始的行计数,然后按添加的字段对其进行排序,然后再次删除添加的字段。如果你看一下它是如何分阶段工作的,就很容易理解了:
1) 添加用于排序的 2 个前缀字段:
$ awk -F'"' -v OFS='\t' 'NF>1{key=$4; cnt=0} {print key, ++cnt, $0}' file
UK: Button 1 (SG) 1 #EXTINF:-1 tvg-id="Button.uk" tvg-name="UK: Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: Button 1 (SG)
UK: Button 1 (SG) 2 #http://website.info:8080/live/xxxxxxxx/xxxxxxxx/112233.ts
UK: London (HD) (720p) 1 ##EXTINF:-1 tvg-id="London.uk" tvg-name="UK: London (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: London (HD) (720p)
UK: London (HD) (720p) 2 #http://website.info:8080/live/xxxxxxxx/xxxxxxxx/36011.ts
2) 使用步骤 1 中添加的 2 个字段对输出进行排序:
$ awk -F'"' -v OFS='\t' 'NF>1{key=$4; cnt=0} {print key, ++cnt, $0}' file |
sort -t$'\t' -k1,1r -k2,2n -s
UK: London (HD) (720p) 1 ##EXTINF:-1 tvg-id="London.uk" tvg-name="UK: London (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: London (HD) (720p)
UK: London (HD) (720p) 2 #http://website.info:8080/live/xxxxxxxx/xxxxxxxx/36011.ts
UK: Button 1 (SG) 1 #EXTINF:-1 tvg-id="Button.uk" tvg-name="UK: Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: Button 1 (SG)
UK: Button 1 (SG) 2 #http://website.info:8080/live/xxxxxxxx/xxxxxxxx/112233.ts
3) 删除在步骤 2 中添加的 1 个字段:
$ awk -F'"' -v OFS='\t' 'NF>1{key=$4; cnt=0} {print key, ++cnt, $0}' file |
sort -t$'\t' -k1,1r -k2,2n -s |
cut -f3-
##EXTINF:-1 tvg-id="London.uk" tvg-name="UK: London (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: London (HD) (720p)
#http://website.info:8080/live/xxxxxxxx/xxxxxxxx/36011.ts
#EXTINF:-1 tvg-id="Button.uk" tvg-name="UK: Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: Button 1 (SG)
#http://website.info:8080/live/xxxxxxxx/xxxxxxxx/112233.ts
请注意,上述方法适用于多行块中任意数量的行,并且相同的方法适用于对多个不同的子字符串进行排序。它也非常高效(在内存中几乎不存储任何内容),并且易于以后调试/增强/维护。
编辑1:根据您在下面的评论和您提供的以下新示例输入,我是您想要的,但我不知道它是否是,因为没有提供预期的输出,而且我能最好地告诉您提供的示例输入已经排序,所以无法判断该工具是否正在做任何事情。
$ cat tst.awk
BEGIN {
FS = "\""
OFS = "\t"
}
/^#/ {
tvgName = $4
nameRowNr = 0
prevGroupTitle = groupTitle
groupTitle = $8
if ( ! ((groupTitle == "_Movies_") && (groupTitle == prevGroupTitle)) ) {
groupNr++
}
}
{
print groupNr, tvgName, ++nameRowNr, $0
}
.
$ awk -f tst.awk file | sort -t$'\t' -k1,1n -k2,2 -k3,3n -s | cut -f4-
#EXTM3U
#EXTINF:-1 tvg-id="BBCRedButton.uk" tvg-name="UK: BBC Red Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC Red Button 1 (SG)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/112233.ts
#EXTINF:-1 tvg-id="BBC1London.uk" tvg-name="UK: BBC ONE (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC ONE (HD) (720p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/36011.ts
#EXTM3U
#EXTINF:-1 tvg-id="BBCRedButton.uk" tvg-name="UK: BBC Red Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC Red Button 1 (SG)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/112233.ts
#EXTINF:-1 tvg-id="BBC1London.uk" tvg-name="UK: BBC ONE (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC ONE (HD) (720p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/36011.ts
#EXTINF:-1 tvg-id="BBC1Scotland.uk" tvg-name="UK: BBC One Scot FHD (1080p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC One Scot FHD (1080p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/24651.ts
#EXTINF:-1 tvg-id="" tvg-name="Act Of Grace" tvg-logo="http://wesite.test:8080/images/skQxxCIxEWuXL4tmPcfDoFjtSZU_small.jpg" group-title="_Movies_",Act Of Grace
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102408.mp4
#EXTINF:-1 tvg-id="" tvg-name="Act Of Valor" tvg-logo="http://wesite.test:8080/images/1Xcd5ci69pVXMPP02DU11Ffq0yY_small.jpg" group-title="_Movies_",Act Of Valor
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96873.mp4
#EXTINF:-1 tvg-id="" tvg-name="Action Jackson" tvg-logo="http://wesite.test:8080/images/rg5WY1SiyPDuTYZs2vgTV0csVbz_small.jpg" group-title="_Movies_",Action Jackson
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96874.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Vengeance" tvg-logo="http://wesite.test:8080/images/r5o6vWPYOQs6bv91gQ8kQs2zQYl_small.jpg" group-title="_Movies_",Acts Of Vengeance
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/107101.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Violence" tvg-logo="http://wesite.test:8080/images/pK9CugRd3DIP0THBH8WlGrvk5vy_small.jpg" group-title="_Movies_",Acts Of Violence
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96711.mp4
#EXTINF:-1 tvg-id="" tvg-name="Adaptation" tvg-logo="http://wesite.test:8080/images/5trb1V5f3IsjpZx2GiuUylowl3W_small.jpg" group-title="_Movies_",Adaptation
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/99509.mp4
编辑 2:鉴于现在在您的问题中发布的更新的示例输入和预期输出,这可能是您想要的:
$ cat tst.awk
BEGIN {
FS = "\""
OFS = "\t"
}
/^#/ {
tvgName = $4
nameRowNr = 0
groupTitle = $8
if ( groupTitle == "_Movies_" ) {
if ( !(groupTitle in groupTitle2nr) ) {
groupTitle2nr[groupTitle] = ++numGroups
}
groupNr = groupTitle2nr[groupTitle]
}
else {
groupNr = ++numGroups
}
}
{
print groupNr, tvgName, ++nameRowNr, $0
}
.
$ awk -f tst.awk file | sort -t$'\t' -k1,1n -k2,2 -k3,3n -s | cut -f4-
#EXTM3U
#EXTINF:-1 tvg-id="BBCRedButton.uk" tvg-name="UK: BBC Red Button 1 (SG)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC Red Button 1 (SG)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/112233.ts
#EXTINF:-1 tvg-id="BBC1London.uk" tvg-name="UK: BBC ONE (HD) (720p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC ONE (HD) (720p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/36011.ts
#EXTINF:-1 tvg-id="BBC1Scotland.uk" tvg-name="UK: BBC One Scot FHD (1080p)" tvg-logo="" group-title="ENTERTAINMENT & LIFESTYLE UK",UK: BBC One Scot FHD (1080p)
http://wesite.test:8080/live/XXXXXXXX/XXXXXXXXX/24651.ts
#EXTINF:-1 tvg-id="" tvg-name="Act Of Grace" tvg-logo="http://wesite.test:8080/images/skQxxCIxEWuXL4tmPcfDoFjtSZU_small.jpg" group-title="_Movies_",Act Of Grace
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102408.mp4
#EXTINF:-1 tvg-id="" tvg-name="Act Of Valor" tvg-logo="http://wesite.test:8080/images/1Xcd5ci69pVXMPP02DU11Ffq0yY_small.jpg" group-title="_Movies_",Act Of Valor
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96873.mp4
#EXTINF:-1 tvg-id="" tvg-name="Action Jackson" tvg-logo="http://wesite.test:8080/images/rg5WY1SiyPDuTYZs2vgTV0csVbz_small.jpg" group-title="_Movies_",Action Jackson
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96874.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Vengeance" tvg-logo="http://wesite.test:8080/images/r5o6vWPYOQs6bv91gQ8kQs2zQYl_small.jpg" group-title="_Movies_",Acts Of Vengeance
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/107101.mp4
#EXTINF:-1 tvg-id="" tvg-name="Acts Of Violence" tvg-logo="http://wesite.test:8080/images/pK9CugRd3DIP0THBH8WlGrvk5vy_small.jpg" group-title="_Movies_",Acts Of Violence
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/96711.mp4
#EXTINF:-1 tvg-id="" tvg-name="Adaptation" tvg-logo="http://wesite.test:8080/images/5trb1V5f3IsjpZx2GiuUylowl3W_small.jpg" group-title="_Movies_",Adaptation
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/99509.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creed" tvg-logo="http://wesite.test:8080/images/hKzhV274pkZBSpXfCjUyzbyYKLl_small.jpg" group-title="Drama",Creed
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/102773.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creep Van" tvg-logo="http://wesite.test:8080/images/r2tSTcns0gHVynnLVPwCtTePfOt_small.jpg" group-title="Horror",Creep Van
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/105306.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creepozoids" tvg-logo="http://wesite.test:8080/images/gZ3HBNBYe6hDTsocsXjDYGv0ZXD_small.jpg" group-title="",Creepozoids
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/106831.mp4
#EXTINF:-1 tvg-id="" tvg-name="Creepshow 2" tvg-logo="http://wesite.test:8080/images/qxJWtBb89RaSRgLuz1d6ZuFTfVG_small.jpg" group-title="Horror",Creepshow 2
http://wesite.test:8080/movie/XXXXXXXX/XXXXXXXXX/105307.mp4
上面的脚本比它必须的稍微复杂一些,所以如果/当你将来需要通过调整行来这样做时,添加额外的“组标题”以在工具的同一调用中对所有内容进行排序是微不足道的。if ( groupTitle == "_Movies_" )
评论
上一个:需要检查鸭嘴兽代码(结果)
评论
_Movies_
_Movies_