Reputation: 87
part of my shell script and a variable
-d [% nameoffile %]_pathName
foldername=BOM_details # its just a folder name containing bill of materials
I need to substitute [% nameoffile %] with BOM_details
I successfully tried
sed -i "s/\[\% nameoffile\%\]/$foldername/g" $filename
but the problem is it is adding new line immediately after replacing
what I got
-d BOM_details
_pathName
what I need is
-d BOM_details_pathName
Upvotes: 1
Views: 305
Reputation: 6083
Supposing the variable foldername
contains a newline char or carriage return at the end of the string (how did you initialise this variable?), you can remove it with the following syntax:
sed -i "s/\[\% nameoffile\%\]/${foldername//[$'\r\n']}/g" $filename
Upvotes: 1