The current solution (2025-03-26)
sed -i -r \
-e '/^[[:space:]]*[#;]/d' \
-e '/^[[:space:]]*$/d' \
php.ini &&
sed -i -z 's/\n$//' php.ini
How to remove the trailing newline (LF
) character (the terminal newline, the EOF newline) from a text file using sed
?
The previous solution
sed -i -r '/^[\s\t]*[#;]/d' php.ini
# 2024-07-28
# The previous command does not remove comments from lines indented with spaces (for an unknown reason).
# So I remove these comments using another command below.
sed -i -r '/^\s\+[#;]/d' php.ini
sed -i -r '/^\s*$/d' php.ini
For all *.ini
files in the current folder and subfolders:
The current solution (2025-03-26)
find . -name '*.ini' -type f \
-exec sed -i -r \
-e '/^[[:space:]]*[#;]/d' \
-e '/^[[:space:]]*$/d' \
{} + \
-exec sed -i -z 's/\n$//' {} +
How to remove the trailing newline (LF
) character (the terminal newline, the EOF newline) from a text file using sed
?
The previous solution
find . -name '*.ini' -type f -exec sed -i -r '/^[\s\t]*[#;]/d' {} +
# 2024-07-28
# The previous command does not remove comments from lines indented with spaces (for an unknown reason).
# So I remove these comments using another command below.
find . -name '*.ini' -type f -exec sed -i -r '/^\s+[#;]/d' {} +
find . -name '*.ini' -type f -exec sed -i -r '/^\s*$/d' {} +