This script pulls out the matching "Group" Sports from my file to the output emby_sports.m3u. I have all the usual groups I.E. "News", "General Streams", "Movies".

Is it possible to adapt this script to "Pull all the groups" in one run and separate them into multiple files, or do I need a separate script for each one I need to pull?

This pulls the Group "Sports" Only....

while read -r LINE || [ -n "$LINE" ]; do
awk '/group-title="Sports"/{nr[NR]; nr[NR+1]}; NR in nr'
sed -i '1i #EXTM3U' emby_iptv_tmp.m3u
done < iptv_download.m3u
mv emby_iptv_tmp.m3u emby_sports.m3u
rm iptv_download.m3u

Here's an example of the output desired for all the lines that contain "Sports". I would like this to output all the groups, "General Streams", "Kids", "News" in one run.

Do I just repeat the awk statement and output over and over again as I have done with multiple scripts or is there some awk formatting that will do this on a one liner?

#EXTINF:-1 tvg-ID="" tvg-name="AU: Fox NRL League HD" tvg-logo="" group-title="Sports",AU: Fox NRL League HD
#EXTINF:-1 tvg-ID="Golf Channel CA" tvg-name="CA: Golf Channel UHD" tvg-logo="" group-title="Sports",CA: Golf Channel UHD
#EXTINF:-1 tvg-ID="Golf Channel CA" tvg-name="CA: Golf Channel" tvg-logo="" group-title="Sports",CA: Golf Channel
#EXTINF:-1 tvg-ID="HPItv" tvg-name="CA: HPItv (HORSE RACING)" tvg-logo="" group-title="Sports",CA: HPItv (HORSE RACING)

I don’t know awk well enough, I’d just use grep and loop over the group names as follows:

for i in Sports News" Movies "General Streams"
  <input.m3u grep --no-group-separator -A1 'group-title="'"$i"\" >"$i.m3u"
  sed -i '1i #EXTM3U' "$i.m3u"

This saves the output in files called simply by the group name, e.g. Sports.m3u and General Streams.m3u.

The GNU parallel Install parallel equivalent to this loop is:

parallel '<input.m3u grep -A1 group-title=\"{}\" >{}.m3u;sed -i "1i #EXTM3U" {}.m3u' ::: Sports News Movies "General Streams"
  • @EODCraftStaff please edit and add this to your question! – dessert Nov 5 '18 at 23:08
  • Ok it's randomly placing -- these in the m3u and it crashes the VLC player...any ideas? There on a line all by thereselves. I'll try parallel.... – EODCraft Staff Nov 5 '18 at 23:23
  • Ok, that's called a group separator and this works in the command.... --no-group-separator – EODCraft Staff Nov 6 '18 at 0:07
  • LOL I actually have a group called 24/7. :) Separate Script. – EODCraft Staff Nov 6 '18 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.