How to add an empty line in text file using shell script?
bash
Solution
i've read your comment "it's giving each and every line space,but i want only before st^". So you can insert new line before st^ with this code:
$cat /tmp/tt.txt | sed 's/^st\^/\n\0/g'
For example:
$ echo '
st^flower
p^rose
p^jasmine
st^animals
p^bear
p^elephant' | sed 's/^st\^/\n\0/g'
Works fine for me.
Problem
This is my code; the "test.txt" file contains more empty lines and empty space apart from tab. I want to remove that empty space and empty lines as well but I need one empty line before starting `st^`. How to do it? ``` sed "s/^[ ]*//" -i test.txt cat $2 > /tmp/tt.txt sed '/^$/d' test.txt > /tmp/tt.txt echo " " >> test.txt echo " " >> /tmp/tt.txt mv /tmp/tt.txt test.txt ``` I am getting output like: ``` st^flower p^rose p^jasmine st^animals p^bear p^elephant ``` I want output like: ``` st^flower p^rose p^jasmine st^animals p^bear p^elephant ```