#!/bin/bash OIFS=$IFS IFS=' ' IDX=1 # The -r option keeps the backslash from being an escape char. read -r line while [[ $? -eq 0 ]] do # trim spaces, tabs of line temp=`echo ${line} | awk '{gsub(/^ +| +$/,"")}1' | awk '{gsub(/^ +| +$/,"")}1'` c=${temp:0:1} if [ "${c}" == "[" ]; then echo "${IDX}" IDX=$(( IDX + 1 )) # index of ']' CIDX=`awk -v a="${temp}" -v b="]" 'BEGIN{print index(a,b)}'` CIDX=$(( CIDX - 2 )) # get rid of "[]" temp=${temp:1:CIDX} descr=${temp#* } timeline="" if [ "${descr}" == "${temp}" ]; then timeline=${descr} descr="" else DLEN=${#descr} SLEN=${#temp} TLEN=$(( SLEN - DLEN - 1 )) timeline=${temp:0:TLEN} fi tbegin=${timeline%-*} tend=${timeline#*-} echo "00:${tbegin%.*},000 --> 00:${tend%.*},000" if [ ${#descr} -gt 0 ]; then echo "(${descr})" fi else echo "${temp}" fi read -r line done IFS=$OIFS