문제

I have a large text file that looks like:

string1
string2

string3
string4
string5

string6
string7
string8
string9

I don't care which programming language I have to use to solve it, I just want to remove lines that is only newline from that text file. I hope you have suggestion...

EDIT:

I can use Objective-C, Java, Bash, and a little C++.

The problem is if I remove all newlines or use it as a delimiter, the whole text will be compressed into one line...

도움이 되었습니까?

해결책

grep -v '^$' oldfile > newfile

^$ is a regular expression that matches an empty line. ^ matches the beginning of the line, $ matches the end of the line, and there's nothing between them. The -v option to grep means to print all lines that don't match the regular expression.

To learn about regular expressions, go to regular-expressions.info

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top