I have shell script (.sh) and I'm trying to insert contents of a file onto another file using the following commands but I it's throwing an error "sed: -e expression #1, char 28: unknown option to `s'":
filename="/home/user1/filename.txt"
contents=$(du -sh /var/log/test.log)
hostname > $filename
sed -i "/test_string/ s/$/, $contents" $filename
I can't seem to figure out where the underlying issue is. Can someone please help?
Example:
filename=/home/user1/filename.txt
hostname = server1.mydomain.com
So the content of $filename
is server1.mydomain.com
after running hostname > $filename
.
The output of du -sh /var/log/test.log
command is let say 1.3M /var/log/test.log
So running sed -i "/mydomain.com/ s/$/, $contents" $filename
should update the content of the following filename to:
server1.mydomain.com, 1.3M /var/log/test.log
But as I mentioned above, it's throwing an error.