I searched and found “echo -n” and “printf” are solution for this, but they are working a bit quirky on my machines.
here:
[wadhwaso@nxnixd01 ~]$ echo "hello" >> test
[wadhwaso@nxnixd01 ~]$ cat test
hello
[wadhwaso@nxnixd01 ~]$ echo -n "world" >> test
[wadhwaso@nxnixd01 ~]$ cat test
hello
world
[wadhwaso@nxnixd01 ~]$ echo -n " seriously?" >> test
[wadhwaso@nxnixd01 ~]$ cat test
hello
world seriously?
same is the case with “printf”. It works 2nd 3rd 4th time and so on but not the first time.
I am not very comfortable with awk and sed, thats why I wanted to use these.
If I dont have any choice can someone tell me how to add “elevator=noop” in /etc/grub.conf via awk or sed ??
Answer:
sed -i '$s/$/,string/' file ..
The
-noption controls whether a newline is added at the end of the echo. That very firstecho "hello"writeshello\nto the file; that’s where the newline is coming from.To add a kernel option try one of these. Each of them searches for the
kernelline in grub.conf and appends ” elevator=noop” to the end.