我有一个文本文件,里面有一些空白行。也就是说,这些行上没有任何内容,只是占用了空间。
它看起来像这样:
The
quick
brown
fox jumped over
the
lazy dog
我需要它看起来像这样:
并且我希望你能将其翻译成这种格式:
The
quick
brown
fox jumped over
the
lazy dog
如何去除空行并只保留有内容的行,将它们写入一个新文件?
以下是我所知道的方法:
$file = fopen('newFile.txt', 'w');
$lines = fopen('tagged.txt');
foreach($lines as $line){
/* check contents of $line. If it is nothing or just a \n then ignore it.
else, then write it using fwrite($file, $line."\n");*/
}
file('tagged.txt')
? - Jonsed
命令:sed -e '/^$/d' tagged.txt > newFile.txt
。 - Gumbo