How to remove empty lines containing only ends of lines $?
I have a file:
cat -E extracted_numbers.txt
11.47$
0.32$
$
1.37192$
-4.$
7.$
20.$
13.$
$0.
15000$
15000.$
$
2.87$
$.6
47.$
$00.
0.0000000000000000$
0.0000000000000000$
$
0.0000000000000000$
0.0000000000000000$
$
0.0000000000000000$
0.0000000000000000$
$
0.0000000000000000$
0.0000000000000000$
$
0.0000000000000000$
0.0000000000000000$
$
0.0000000000000000$
0.0000000000000000$
$
0.0000000000000000$
0.0000000000000000$
$
0.$
0.$
0.$
$.
0.$
0.$
$
$0.
279.33$
$
How to remove the empty lines or the lines that include only the end of the line? I tried:
sed -i '/^$/d' extracted_numbers.txt
and
grep -v '^$' extracted_numbers.txt
Why it does not work? Has anyone an idea what next command I can use? Thank you
You can capture lines that contain something (.
in an RE matches any character):
grep . file >file.new
If you find this still matches your supposedly blank lines then you probably need to fix up Windows line endings:
tr -d 'r' <file | grep . >file.new
Or maybe your unwanted blank lines actually contain whitespace (possibly including Windows line endings):
grep '[^[:space:]]' <file >file.new
If you want an edit-in-place this approach is portable for a file named file
(if it is a known file name you may be able to omit the occurrences of --
like in the examples above):
grep . <file >"file.$$.tmp" && mv -f -- "file.$$.tmp" "file"
rm -f -- "file.$$.tmp"