【发布时间】:2016-01-20 14:10:17
【问题描述】:
我正在编写一个 bash 脚本来为 hadoop 更改 xml 文件中的一些值。我以前用过一点点 sed,没什么太复杂的。
这是有问题的行:
sed "s@<configuration>@${toedit}@g output.txt" /usr/local/hadooptest/etc/hadoop/core-site.xml
我正在使用 output.txt 来测试输出。完成的脚本会将存储在 $toedit 中的代码插入到:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
</configuration>
我想用变量 $toedit 替换 configuration 标签。在 $toedit 我保存了:
toedit='<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/app/hadoop/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:54310</value>
</property>'
通过谷歌搜索过去出现的类似问题,我知道我的变量有问题(由于 {} 括号或 '' - 短篇小说是空的)但我不知道为什么!
我尝试过单引号、双引号、无引号、我在网上看到的不同 sed 选项(其中一些我只是按照给定的答案并希望得到最好的结果),但我没有运气。
我认为这有点小,或者有些愚蠢,但我碰壁了!我在整个网站上都看到了 sed 问题,但我发现的选项对我没有帮助。
我应该说这一切都包含在一个 bash 脚本中,最终结果是根据本教程安装和配置 hadoop:http://www.bogotobogo.com/Hadoop/BigData_hadoop_Install_on_ubuntu_single_node_cluster.php
我正在练习脚本,我认为这将是一个很好的挑战!
谢谢
【问题讨论】:
标签: xml bash variables replace sed