I need to remove empty new lines from text file in terminal.
Example file
123
123
123
123
123
123
I've searched in google a bit but only solution found was sed '/^$/d' myFile > tt and it does not help. I still got these empty new lines.
|
I need to remove empty new lines from text file in terminal. Example file
I've searched in google a bit but only solution found was |
||||
|
You can use grep for this purpose. Try: Your command also seems to work:
|
||||
|
|
|
The solution you posted will delete empty lines:
This won't work for lines that contain spaces, or hard tabs, or any other kind of whitespace, including carriage returns. This means, if your text file originated on Windows, that solution probably won't work. On Unix, lines are simply separated with a line feed. On Windows, they are separated with a carriage return and a line feed. Here's one way to delete empty lines, compatible with Windows' text format:
If you want to delete lines that contain only whitespace, this should work (on Ubuntu at least):
|
|||
|
|
|
Here's another solution:
( |
|||
|
|
|
Using AWK: NF is AWK's in-built variable that stores the number of fields in each record. When used by it self, it will print only those lines where NF!=0.
|
|||
|
|
sed '/^[ \t]*$/d' original.txt > emptyRemoved.txt. Also, I hope you realize thatttis the file with the empty lines removed. Your suggested solution doesn't affectmyFile. – ladaghini Nov 9 '11 at 13:12-iflag. – Kevin Nov 24 '11 at 3:34