Parsing delimited file

I'll have a file with ever changing lengths depending on the report. Right now it is stored by : delimiter. My question is how do I parse through this b/c it will be changing lengths each time.

Example:

1:2:3:4:5
1:2:3:4:5:6:7:8:9
1:2:3

I want to take each one and place in newline for further work.

Output desired:

1
2
3
4
5

1
2
3
4
5
6
7
8
9

1
2
3

Any help is appreciated. Thanks!

Awk

cat file | awk -F : '
{  for (i=1;i<=NF; i++) {
        print $i
        }
   print ""
}'

ksh, bash, dash, ...

oifs="$IFS"
cat file | while read line
do
        IFS=":"
        for fld in $line
        do
                echo "$fld"
        done
        IFS="$oifs"
        echo
done
1 Like

How about:

sed -e 's/$/\n/g' -e 's/:/\n/g' infile
1 Like

Fantastic. Thank you both. I came up with another....

tr -s ':' '\n' < infile

That doesnt seem to leave the double newline between records

awk '$1=$1' FS=":" OFS="\n" ORS="\n\n" infile