Need to loop file data based on delimiter

My file has data that looks like below:

more data.txt

I wish to display each string seperated by a delimiter :

Expected output:

I tried the below but I m not getting every split string on a new line.

#!/bin/bash
for i in `sed 's/:/\\n/g' data.txt`;
do
echo -n "$i"
done

Can you please suggest what should I do to fix the problem ?

Using shell built-ins:-

while read line
do
        for file in ${line//:/ }
        do
                print $file
        done
done < data.txt

OR

tr ':' '\n' < data.txt
1 Like

Using a bash array

while IFS=: read -a lines
do
  printf "%s\n" "${lines[@]}"
done < data.txt

or

while IFS=: read -a lines
do
  for file in "${lines[@]}"
  do
    printf "%s\n" "$file"
  done
done < data.txt