0

I am trying to update my hadoop-env.sh file such that I replace a commented parameter with a new one. I am new to the whole concept and after a lot of searching I ended up doing the following:

sed -i '/^export JAVA_HOME=/ s:.*:export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport HADOOP_HOME=/usr/local/hadoop\n:' $HADOOP_HOME/etc/hadoop/hadoop-env.sh

The part of file that I am trying to update looks like:

# The java implementation to use. By default, this environment
# variable is REQUIRED on ALL platforms except OS X!
# export JAVA_HOME=

And desired outcome is:

# The java implementation to use. By default, this environment
# variable is REQUIRED on ALL platforms except OS X!
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_HOME=/usr/local/hadoop

However, when I cat the hadoop-env.sh file I am getting the same content as before. I have to mention that I am running this in Dockerfile using the following:

RUN sed -i '/^export JAVA_HOME=/ s:.*:export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport HADOOP_HOME=/usr/local/hadoop\n:' $HADOOP_HOME/etc/hadoop/hadoop-env.sh

I have no idea what I might be missing and any help is much appreciated.

1
  • 3
    It is because there is not any line in your file starting with export JAVA_HOME= . The desired line starts with # export so the anchor in sed /^export matches nothing. You need to modify it accordingly to catch # export Feb 3, 2020 at 21:46

1 Answer 1

0

This was answered in the comments.

Change:

sed -i '/^export JAVA_HOME=/ s:.*:export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport HADOOP_HOME=/usr/local/hadoop\n:' $HADOOP_HOME/etc/hadoop/hadoop-env.sh

To: (adds 2 characters only)

sed -i '/^# export JAVA_HOME=/ s:.*:export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport HADOOP_HOME=/usr/local/hadoop\n:' $HADOOP_HOME/etc/hadoop/hadoop-env.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .