User Tools

Site Tools


linux:remove-multi-blank-lines

Link to this comparison view

linux:remove-multi-blank-lines [2017/12/20 10:34] (current)
percy created
Line 1: Line 1:
 +====== Remove Mutli-Blank lines ======
 +
 +When we coding and can found there has some blank lines, so we need to remove them but just keep one blank line.
 +
 +So here has some solutions
 +  * cat -s
 +  * sed '​N;/​^\n$/​D;​P;​D;'​
 +  * for i in *; do FILE=$(cat -s "​$i"​);​ echo "​$FILE"​ > "​$i";​ done
 +
 +
 +===== Refer =====
 +
 +  * https://​stackoverflow.com/​questions/​922449/​how-can-i-replace-multiple-empty-lines-with-a-single-empty-line-in-bash
 +  * https://​stackoverflow.com/​questions/​922449/​how-can-i-replace-multiple-empty-lines-with-a-single-empty-line-in-bash/​934451#​934451
  
/var/www/dokuwiki/wiki/data/pages/linux/remove-multi-blank-lines.txt · Last modified: 2017/12/20 10:34 by percy