Newline Issue in MacOS Terminal with Shell Script

Hi everyone,

I'm trying to run a shell script in the MacOS terminal to process text files, but I'm having trouble with newline operations. The code is as follow picture:

The goal is to process each line with grep, cut, and tr, and then output it to test.txt with each entry on a new line. However, the script isn't producing newlines between the outputs as expected. Only the first line seems to be formatted correctly, and subsequent lines are not appearing on new lines.

Does anyone have a solution or suggestion for handling newlines properly in this script on MacOS?

Thank you for your help!