awk move txt up one line x2

using awk
iam trying to get the title moved up to the line above
the title is between the first and last dashs
some titles have more dashs than others
also need the video size between the 9th forward slash moved up as well

i have this

https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-hello-bye-hello-1574325303/1080p/index.m3u8
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-hi-bye-see-you-1574325303/720p/index.m3u8
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-hello-you-1574325303/480p/index.m3u8
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-once-upon-a-time-there-was-bear-1574325303/360p/index.m3u8

required output

hello bye hello 1080p
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-hello-bye-hello-1574325303/1080p/index.m3u8
hi bye see you 720p
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-hi-bye-see-you-1574325303/720p/index.m3u8
hello you 480p
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-hello-you-1574325303/480p/index.m3u8
once upon a time there was bear 360p
https://example.com/7p0sM06YtrQZFe2QP_WHlA/1582963669/storage3/movies/7131622-once-upon-a-time-there-was-bear-1574325303/360p/index.m3u8

i have tried this but because the amount of dashs some more some less it will only do part of the last one

awk -F'[-]' '{print $2,$3,$4,$5,$6,$7,$8;print $0}' file

thanks

Hi
What about 'sed'?

sed -r 's%^[^-]*-(.*)-.*/(.*)/.*$%\1 \2\n&%' file
3 Likes

thank you

that works fantastic

1 Like

I see you already got a good answer
but here is a solution in awk instead of sed

awk -F '/' '{tw = split ($8, arr, "-"); i = 2; title = ""; while (i < tw) {title = title arr " "; ++i} print title $9 "\n" $0}' file

there is probably a better way to write this but it works

1 Like

Hi @daustin
You reminded me that I did not remove the dashes in the titles. Thanks

sed -nr 'h;s%^[^-]*-(.*-).*/(.*)/.*$%\1\2%; s/-/ /gp;x;p' file
1 Like