Cat Command Not Reading All Data in Text File

烈酒焚心 提交于 2019-12-07 12:36:55

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/23430936/cat-command-not-reading-all-data-in-text-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!