You are not logged in.
Is it possible to remove spaces from blank lines in possix?
They may even create a new blank line..
Say I have 3 blank lines and the second one contains N spaces.
The problem is they may only be removed from blank lines.
If they are preceding some 'text' they may not be removed..
I have tried things like
s/^[[:space:]]*$/&\n/;
and
/^ *$/d;
but, after removing all blank lines but one with
/^*$/N;/^\n$/D
all blank lines are removed while I want to keep at least one..
Last edited by qinohe (2020-02-06 20:24:19)
Offline
What about only this?
s/^[[:space:]]*$//
So, if I create example as you said, three blank lines and second one has N spaces - input example file "test" has 23 bytes, while afterwards the "output" has only 3 bytes - 1byte/line:
$ sed 's/^[[:space:]]*$//' test > output; ls -la test output
-rw-r--r-- 1 username groupname 23 Feb 6 20:43 test
-rw-r--r-- 1 username groupname 3 Feb 6 20:44 output
Logic clearly dictates that the needs of the many outweigh the needs of the few.
Offline
Thanks, Yes, I get the same result using
sed -e 's/^[[:space:]]*$//' ~/.scripts/tests/space | sed '/^$/N;/^\n$/D' > ~/.scripts/tests/sp
only one line is left which is good.
when however using this strategy on a + 20 lines sed script it fails, I try to edit the result afterwards, see where it gets me.
Offline
If you intend to apply this globally, use G for global:
s/^[[:space:]]*$//g
This should process the whole file with such data.
Logic clearly dictates that the needs of the many outweigh the needs of the few.
Offline
I do already
edit;
I got it it's ugly though..
sed -e'....
sed lines
...' ~/.scripts/tests/space | sed 's/^[[:space:]]*$//g' > ~/.scripts/tests/sp
sed -i '/^$/N;/^\n$/D' ~/.scripts/tests/sp
Thanks for the help;)
Last edited by qinohe (2020-02-06 20:18:03)
Offline