开发者

Create a new file by removing the new line character at the end of file

开发者 https://www.devze.com 2023-03-08 02:41 出处:网络
I have a flat file which contains the following data records between H: and T:. H:20050427 HEADER RECORD

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 f开发者_开发知识库ile and create a new file with data which are present between H: and T:?

Thanks, Arun


If you want to remove all blank lines from your file, why don't you grep for lines that have non-whitespace?

$ grep -e \\S <myfile> > <newfile>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消