Issue
How sed
inserting one blank line on this keep-failing code:
sed -Ee '/^---/{n;/^\s*$/b;i \n' -e 'b}; b; q' -- inserting_one.txt
---
n
WORKING_DIR
To insert one blank line right following ---
line not followed by blank line, then keep the rest going on
---
WORKING_DIR
By using \\n
: sed -Ee '/^---/{n;/^\s*$/b;i \\n' -e 'b}; b; q' -- inserting_one.txt
it inserts two blank line
---
WORKING_DIR
Please help guide correct path, thanks much
Solution
You could use a pattern to match 3 or more hyphens and check that there is at least a single non space on the following line.
sed '/^---\+$/{N;s/\n[[:space:]]*[^[:space:]]/\n&/}' inserting_one.txt
Explanation
/^---\+$/
Match 3 or more hyphens on the whole line{
Start commands separated by ;N;
Pull the next line into the pattern spaces/
Start substitution\n[[:space:]]*[^[:space:]]
Match a newline, optional spaces and a non whitespace char to make sure the next line is not empty/\n&/
Substitute with a newline and the rest of what is matched
}
End
Output
---
WORKING_DIR
Answered By - The fourth bird Answer Checked By - David Marino (WPSolving Volunteer)