Suppose i have a file "xyz.txt" which contains
abcdef
ghijklm
nop
Now in want to add "qrst" to the last line such that the file becomes
abcdef
ghijklm
nopqrst
P.S:The o/p i need is
abcdef
ghijklm
nopqrst (and not) nop
qrst
Suppose i have a file "xyz.txt" which contains
abcdef
ghijklm
nop
Now in want to add "qrst" to the last line such that the file becomes
abcdef
ghijklm
nopqrst
P.S:The o/p i need is
abcdef
ghijklm
nopqrst (and not) nop
qrst
Try this..
echo "$(cat file)qrst" >temp
mv temp file
O/p:
cat file
abcdef
ghijklm
nop
echo "$(cat file)qrst"
abcdef
ghijklm
nopqrst
Using sed
$ cat xyz.txt
abcdef
ghijklm
nop
$ sed '$ a\qrst' xyz.txt
abcdef
ghijklm
nop
qrst
$ sed '$ a\qrst' xyz.txt > abc.txt
$ mv abc.txt xyz.txt
$ cat xyz.txt
abcdef
ghijklm
nop
qrst
$
I seem to have misunderstood the requirement. Hope below is the required soln.
$ sed '$ s/^\(.*\)$/\1qrst/' xyz.txt
abcdef
ghijklm
nopqrst
awk '{ printf "\n%s", $0 }END{ printf "abcdefghijkl\n" }' filename
sed '$s/$/&qrst/' input_file