Missing newline character?

2019-02-26 05:21发布

问题:

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..

回答1:

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


标签: linux shell hdfs