缺失换行符? [英] Missing newline character?

查看:203
本文介绍了缺失换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从HDFS复制了一个文件到我的本地文件系统(全部在RH linux上)。但是,复制后,如果我 cat 该文件,我会看到以下内容:

  [me @ ac12〜] $ cat file_copy 
0 | name | string
1 | phone | string
2 | age | string [me @ ac12〜] $

我所期望的是:

  [me @ ac12〜] $ cat file_copy 
0 | name | string
1 | phone | string
2 | age | string
[me @ ac12 〜] $

您可以看到第一只猫似乎缺少换行符,而shell提示与最后一行位于同一行。为什么会这样,我该如何诊断问题?编辑:我不能编辑输出文件(嗯,也许我可以但我真的不想要 - 我宁愿在源头解决问题)。我想知道为什么没有换行符。

解决方案

您可以使用 sed 在最后一行后添加换行符:

  sed -i.bak $'$ s / $ / \\ / file_copy 

编辑:



或者使用(感谢@JonathanLeffler):

  echo''>> ; file_copy 


I've copied a file from HDFS into my local file system (all on RH linux). However, after the copy, if I cat the file, I see the following:

[me@ac12 ~]$ cat file_copy
0|name|string
1|phone|string
2|age|string[me@ac12 ~]$

What I expected was this:

[me@ac12 ~]$ cat file_copy
0|name|string
1|phone|string
2|age|string
[me@ac12 ~]$

You can see that a newline seems to be missing in the first cat, and the shell prompt is on the same line as the last line. Why would this be and how can I diagnose the issue?

EDIT: I can't edit the output file (well, maybe I could but I really don't want to - I'd rather fix the problem at the source). I want to know why there is no newline character..

解决方案

You can use this sed to add a newline after last line:

sed -i.bak $'$s/$/\\n/' file_copy

EDIT:

Or else use (thanks to @JonathanLeffler):

echo '' >> file_copy

这篇关于缺失换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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