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
This appending task can be done by using 'echo' and 'tee' commands. Using '>>' with 'echo' command appends a line to a file. Another way is to use 'echo,' pipe(|), and 'tee' commands to add content to a file.
The most used newline character If you don't want to use echo repeatedly to create new lines in your shell script, then you can use the \n character. The \n is a newline character for Unix-based systems; it helps to push the commands that come after it onto a new line.
Alternatively, you can use the printf command (do not forget to use \n character to add the next line). You can also use the cat command to concatenate text from one or more files and append it to another file.
The G sed command appends a newline followed by the content of the hold space (here empty as we don't put anything in it) to the pattern space. So it's a quick way to add an empty line below that matched line.
To output empty line use this:
echo -en '\n'
e - interprets \n
n - outputs no empty line on the end, so there is no mess with double empty lines
Use single quotes to prevent shell from interpreting chars as end of line.
echo -e "\n"
With double quotes, it must work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With