Skip to content

Instantly share code, notes, and snippets.

@aaccioly
Created November 27, 2016 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaccioly/f9f87334ebaf4c80882cbb1977ddff96 to your computer and use it in GitHub Desktop.
Save aaccioly/f9f87334ebaf4c80882cbb1977ddff96 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Extracts Artist;Album and Title from a CSV file exported by Mp3tag
if [ $# -ne 1 ]; then
echo usage: cleanMp3tagCSV file
exit 1
fi
ORIGINAL_FILE=$1
#Change encoding
RESULT="$(iconv -f UCS-2 -t UTF-8 -c $ORIGINAL_FILE)"
# Select first four columns
RESULT="$(cut -d';' -f4-10 --complement <<< "$RESULT")"
# Reorder columns
RESULT="$(awk 'BEGIN {FS=OFS=";"} {print $2,$3,$1}' <<< "$RESULT")"
# Sort while keeping the first line and removing the last
echo $(head -n 1 <<< "$RESULT")
sort -t\; -k 1,1d -k 2,2d -k 3,3d <<< "$(sed '1d;$d' <<< "$RESULT")"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment