#!/bin/awk -f # rockbox to meizu FM preset file converter BEGIN { FS = ":" # src: file field separator chlimit = 50 # dst: limit of num. of channels in the file maxnlen = 16 # dst: maximum length of station name adddot = 0 # dst: add dot at the end of shortened names? addchr = "." # dst: character to be added when shortening mhzsrc = 1000000 # src: 1 MHz in source file mhzdst = 100 # dst: 1 MHz in destination file print "[FM]" # dst: header of the destination file channel = 1 # dst: channel counter, first channel mhzcnv = mhzsrc / mhzdst # frequency convert ratio } #/^[[:space:]]*[[:digit:]]{8,9}[[:space:]]*:[[:space:]]*.*[[:space:]]*$/ # more exact POSIX regexp /^[[:space:]]*[[:digit:]]+[[:space:]]*:[[:space:]]*.*[[:space:]]*$/ { if(channel > chlimit) exit nlen = length($2) adch = "" if(nlen > maxnlen) { if(adddot) { nlen = maxnlen - 1; adch = addchr } else nlen = maxnlen } printf("CH%02d=%05d, %s\n", channel, $1 / mhzcnv, substr($2, 1 , nlen) adch) channel++ }