Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cat Command Not Reading All Data in Text File

Tags:

bash

cat

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!

like image 463
user3521263 Avatar asked Dec 15 '22 23:12

user3521263


1 Answers

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.

like image 73
toth Avatar answered Jan 02 '23 06:01

toth