Link to home
Start Free TrialLog in
Avatar of peter
peterFlag for United States of America

asked on

sed script for large file

Hey everyone,

I have a rather large edit I need to make using sed. But the outcome is the file is doubled.

I need to take this paragraph....
java -jar -Dbase_dir=$BASE_DIR -Dlog_home=$LOG_HOME -Dserver.port=$SERVER_PORT -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false $BIN_DIR/xxxxx-boot-0.0.1-SNAPSHOT.jar --spring.profiles.active=${ENV} --static.content.base=$BASE_DIR/static_29376 --server.context-path=/ --applicationURL=https://test.xxxxx.com --site_base=https://test.xxxxx.com/public --pySurveyConsoleUrl=https://test.xxxxx.com/adm/login/ &

and turn it into this

java -jar -Dbase_dir=$BASE_DIR -Dlog_home=$LOG_HOME -Dserver.port=$SERVER_PORT -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false $BIN_DIR/xxxxx-boot-0.0.1-SNAPSHOT.jar --spring.profiles.active=${ENV} --static.content.base=$BASE_DIR/static_29376 --server.context-path=/ --applicationURL=https://ohiotest.xxxxx.com --site_base=https://ohiotest.xxxxx.com/public --pySurveyConsoleUrl=https://ohiotest.xxxxx.com/adm/login/ &

the only things that need to change is the references to ohiotest which replace test

When I try to accomplish that using this sed script, I get both paragraphs squished together. meaning, doubled up, and not one edited paragraph.

Heres the sed script I'm using.....

sudo sed -i 's#changethismess#tothatmess#g' /home/somedirectory/somefile

So the outpout looks like this....which is doubled up....

java -jar -Dbase_dir=$BASE_DIR -Dlog_home=$LOG_HOME -Dserver.port=$SERVER_PORT -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false $BIN_DIR/xxxxx-boot-0.0.1-SNAPSHOT.jar --spring.profiles.active=${ENV} --static.content.base=$BASE_DIR/static_29376 --server.context-path=/ --applicationURL=https://test.xxxxx.com --site_base=https://test.xxxxx.com/public --pySurveyConsoleUrl=https://test.xxxxx.com/adm/login/ &java -jar -Dbase_dir=$BASE_DIR -Dlog_home=$LOG_HOME -Dserver.port=$SERVER_PORT -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false $BIN_DIR/xxxxx-boot-0.0.1-SNAPSHOT.jar --spring.profiles.active=${ENV} --static.content.base=$BASE_DIR/static_29376 --server.context-path=/ --applicationURL=https://ohiotest.xxxxx.com --site_base=https://ohiotest.xxxxx.com/public --pySurveyConsoleUrl=https://ohiotest.xxxxx.com/adm/login/ &
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peter

ASKER

Youre correct, this works great, thanks!
sed -e "s/test/ohiotest/g" /home/user/dir/bin/start_w_jmx.sh
Avatar of peter

ASKER

I'm sorry to add, while the transformation works, the original file is unaltered.
look at using the -i option to indicate you want the change to occur to the file .

sed -i.bak -e "s/test/ohiotest/g" /home/user/dir/bin/start_w_jmx.sh

if replaced, the original file will be backed up
as /home/user/dir/bin/start_w_jmx.sh.bak
Avatar of peter

ASKER

that works, thanks!