returning split fields

I have a variable with data in this format

field1;field2;field3

I wanted to split the variable like this

field1
field2
field3

this statement was working fine echo $key_val | awk '{gsub(";" , "\n"))'

but sometimes we get the data in the variable in this format key_val="field1"

if this value is sent through the above statement it does'nt return any value

I want to write a short shell script which will return the data like

field1
field2
field3

when the input was like field1;field2;field3

and just field1 when the input was just like that

I think this way will work

count=0
count=`echo $key_val | sed -cd ";" |wc -c`

if [[ $ count -eq 0 ]]
then
echo $key_val
else
echo $key_val | awk '{gsub(";" , "\n"))'
fi

However it seems too long and cumbersome way of implementing it,do you have any suggestions how i can make the code more compact or more efficient

I am working in the korn shell

Thanks

Mervin

tr ';' '\n' < file

or

sed 's/;/\n/g' file

or

awk 'BEGIN{FS=";"} {for(i=1;i<=NF;i++)print $i}' file

Thanks but dont i need to have the flow to come in from a file for the above solutions ?or can i can have it like this ?

output_val=`echo $key_val | sed 's/;/\n/g'`

or any of the solutions you had suggested
Thanks for the help

Mervin

just a clarification,what if there is no ; at the end of the field value say something like this "AAAA" ,will it still return the value

I could test and try it but i dont have access to an unix box right now

thanks

Mervin