We can remove blank lines from a file in shell scripting through various command awk,sed etc. using sed command it is very simple..
sed '/^$/d' myFile > outputfile
'^$' character here represent blank line and 'd' stand for deleting.
Note that sed command do not directly make changes to original file, it just display the output on screen, output can be redirected to new file as shown using '> outputfile'.
same can be achived using grep command as below.
grep -v '^$' myFile > outputfile
sed '/^$/d' myFile > outputfile
'^$' character here represent blank line and 'd' stand for deleting.
Note that sed command do not directly make changes to original file, it just display the output on screen, output can be redirected to new file as shown using '> outputfile'.
same can be achived using grep command as below.
grep -v '^$' myFile > outputfile
No comments:
Post a Comment