Cat命令无法读取文本文件中的所有数据 [英] Cat Command Not Reading All Data in Text File

查看:553
本文介绍了Cat命令无法读取文本文件中的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一天尝试使用bash,因此我为这个可能很愚蠢的问题表示歉意。...

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

我有一个制表符分隔的文本文件,行距为24行5列。例如,这是前几行:

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

我正在尝试使用cat命令来显示文本文件中的所有数据。这是我用vi编辑器编写的代码:

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

我的输出是:

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!

推荐答案

我猜测文件中的行以回车符(\r字符)结尾,而不是新行。
导致每一行都被下一行覆盖,而您只会看到最后一行。
尝试做

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.

这篇关于Cat命令无法读取文本文件中的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆