I have a textfile with a bunch of data and lines like SID: 1 - SN: 0123456789
scattered all over the file. All lines are delimited with CR/LF (Windows)
In bash I create an array with unique Serial Numbers:
sn=($(cat ./serials |awk '/SN: / { print $3 }' FS=': '|sort -u;))
So far so good, but each array member contains a CR at the end:
echo "${sn[0]}:test"
prints :test56789
instead of 0123456789:test
I can fix it with tr -d '\r'
like this:
sn=($(cat ./serials |tr -d '\r'|awk '/SN: / { print $3 }' FS=': '|sort -u;))
but I doubt if this is the best approach. Is there a way to remove the CR in the awk
command?