Created
July 27, 2013 18:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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