Skip to content

Instantly share code, notes, and snippets.

@mmaassen
Created July 27, 2013 18:07
Show Gist options
  • Save mmaassen/6095735 to your computer and use it in GitHub Desktop.
Save mmaassen/6095735 to your computer and use it in GitHub Desktop.
Was cutting a m3u8 file containing IPTV channels. Figured the best way to sort them is by scripting it just for the fun of it. m3u8sort.sh does what it says it sorts it.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: $0 <path/to/m3u8>"
exit
fi
FILE=$1
TMPFILE="$FILE.new"
counter=0
rm -f "$TMPFILE"
touch "$TMPFILE"
echo "#EXTM3U" >> "$TMPFILE"
cat "$FILE" | while read line; do
if [[ "$line" = *EXTINF* ]]; then
let counter=counter+1
Channel=`echo $line | cut -d',' -f2`
echo "#EXTINF:$counter,$Channel" >> "$TMPFILE"
elif [[ "$line" = *EXTM3U* ]]; then
echo -n ""
else
echo $line >> "$TMPFILE"
fi
done
mv "$FILE" "$FILE.back"
mv "$TMPFILE" "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment