通过删除文件末尾的换行符来创建新文件
我有一个平面文件,其中包含 H: 和 T: 之间的以下数据记录。
H:20050427 HEADER RECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
T:20050427 TRAILER RECORD
[blank space]
[空白] 是在 T: 之后创建的没有记录的新行(回车键):
如何从文件中删除空格(如果存在)并使用 H: 之间存在的数据创建一个新文件和T:?
谢谢, 阿伦
I have a flat file which contains the following data records between H: and T:.
H:20050427 HEADER RECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
0000000 00000 000000000 123456 00 654321 DATARECORD
T:20050427 TRAILER RECORD
[blank space]
[blank space] is a new line (carriage return key) created with no records after T:
How do I remove the blank space(s) (if present) from the file and create a new file with data which are present between H: and T:?
Thanks,
Arun
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想从文件中删除所有空白行,为什么不 grep 查找非空白行呢?
\S
是“非空白”的简写\
必须进行转义,以便 shell 能够通过它,这就是为什么需要两个反斜杠。If you want to remove all blank lines from your file, why don't you grep for lines that have non-whitespace?
\S
is shorthand for "non-whitespace" The\
has to be escaped so that the shell passes it through, which is why you need two backslashes.