19 Sept 2012

Deleting empty line in file using unix


The following unix code for the deleting empty or blank line from a file.

sed '/^$/d' file_name > temp_file
mv temp_file file_name

Here is what happens:
  • sed '/^$/d' file_name removes all empty lines from the file file_name and outputs the result in the console,
  • It redirects the output into a temporary file called temp_file,
  • mv temp_file file_name moves the temporary file temp_file to file_name.

No comments:

Post a Comment