Question

This is my first day trying to use bash, so I apologize for this probably stupid question....

I have a tab delimited text file 24 rows by 5 columns. Here is the first couple of lines for example:

rad97pt_1   p97_1   raddptdz97_1    dp97_1  rad97_1 w97_1
rad97pt_2   p97_2   raddptdz97_2    dp97_2  rad97_2 w97_2
rad97pt_3   p97_3   raddptdz97_3    dp97_3  rad97_3 w97_3

I'm trying to use the cat command to display all the data in text file. Here is my code written in a vi editor:

#!/bin/bash
cat filelist97.txt

My output is:

rad97pt_24      p97_24  raddptdz97_24   dp97_24  rad97_24 w97_24

Why is it only outputting the last line of the text file? Thanks again for the help!

Was it helpful?

Solution

I'm guessing the lines in your file end in carriage returns (\r character) not followed by new lines. That causes each line to be overwritten by the next one, and you only see the last one. Try doing

 tr '\r' '\n' <filelist97.txt

If that fixes it, you should consider fixing the file.

OTHER TIPS

After the accepted answer failed to provide results I downloaded dos2unix via homebrew:

brew install dos2unix

This application will report text file's line endings, and allow you to change them.

In my case the following dos2unix command identified the line endings:

dos2unix -i /Users/john/Desktop/files.txt

And this command changed the line endings:

mac2unix /Users/john/Desktop/files.txt

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top