The other day, I exported a playlist to text with iTunes in the hopes of making a quick CD Jacket. However, the playlist had a million fields, many of them utterly superfluous. So I figured I could just rid myself of the fields I didn't want with cut. Running into the Mac to UNIX line break problem with carriage returns (see robg's note), I solved it and did this all rather simply on my first try. But breaking out the old awk manual, I made a script to print the track name, artist, and time in correct form (iTunes saves it as the flat number of seconds, so it needs to be converted):
awk '{ gsub("\r", "\n"); print $0;}' Playlist.txt | \
awk 'BEGIN {FS="\t"} {if (NR == 1) printf "%s\t%s\t%s\n", $1, $2, $7; \
else if (NF != 0) printf "%s\t%s\t%i:%i\n", $1, $2, int($7/60), $7%60 }'
With a little work from TextEdit, it can be made to look pretty. I don't know if this will help anyone else, but it certainly saves me some time.
[robg adds: Mac to UNIX line breaks were covered in one of the earliest hints we ran here, so I've moved the explanation of the problem to the second part of this hint -- there's some new info there, so if you're interested in learning more about the differences, read the rest of the hint.]Mac vs. UNIX line breaks: From time to time I run across a Mac text file that I want to do processing with awk, cut or paste in Unix. However, TextEdit and most mac programs generate Mac text files, which have new lines delimited by the Carriage Return character (character #0D, 'r'), while most unix commands are looking for a file with new lines marked by line feeds (#0A, 'n'). There are a number of ways of getting around this problem - one good site can be found at Indiana University's Knowledge Base. Here are some of the approaches they suggest:
tr:tr '\r' '\n' < macfile.txt > unixfile.txtawk:
awk '{ gsub("\r", "\n"); print $0;}' macfile.txt > unixfile.txt
perl:
perl -p -e 's/\r/\n/g' < macfile.txt > unixfile.txtThe output, of course, doesn't have to be redirected at a file, it can be piped to anything, or just read on the screen.

