Remove End of Line (EOL) whitespace in Files in UNIX/ Ubuntu
Do not miss this exclusive book on Binary Tree Problems. Get it now for free.
In this article, we have demonstrated how to Remove End of Line (EOL) whitespace in Files in UNIX/ Ubuntu using grep and sed commands.
Table of contents:
- Remove EOL whitespace in one file
- Remove EOL whitespace recursively in all files
- Remove EOL whitespace in VI / VIM editor
Remove EOL whitespace in one file
Use the following command in the terminal to remove EOL in a single file (say code.cpp):
sed -i 's/\s*$//' code.cpp
Remove EOL whitespace recursively in all files
If you are working on a project, there will be multiple files in recursive directories and it will be tedious to remove EOL whitespace one by one for each file. We can do it at once for all files.
- List files having End of Line whitespace and ignoring files in a specific directory such as log directory:
grep -ERl -I '\s+
Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.