I need to delete empty lines from a file (with spaces only – not null records).
The following command works only for null rows, but not in case of
spaces:
sed '/^$/d' filename
Can it be done using grep?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
\s*for blank lines containing only whitespace:To save the changes back to the file use the
-ioption:Edit:
The regex
^\s*$matches a line that only contains whitespace,grep -vprint lines that don’t match a given pattern so the following will print all none black lines: