Removing blank line from file

Using sed.
$ sed '/^$/d' withblankline.txt > withoutblankline.txt
Using grep.
$ grep -v '^$' withblankline.txt > withoutblankline.txt

Use following for loop (shell script) to remove all blank lines from all files stored in /home/prabhat/data directory:

#!/bin/sh
files="/home/prabhat/data/*.txt"
for f in $files
do
sed '/^$/d' $i > $i.out
mv $i.out $i
done

Comments

Popular posts from this blog

How do I Use the Linux Top Command?

IOPS measurement