shell去掉空白行、多余空格

去掉空白行:

tr -s ["\012"] < test.txt > newtest.txt


sed -n '/./p' temp_file5 > newtest.txt


grep . temp_file5 > newtest.txt


grep -v '^$' temp_file5 > newtest.txt


去掉多余空格:

cat test.txt | tr -s [:space:]

sed 's/__*/_/g' test.txt     这里,_表示一个空格

你可能感兴趣的:(shell,File)