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/ &
LVL 1
petersystems engineerAsked:
Who is Participating?
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Maybe you have some non-UNIX line breaks in your files.

If I create a file with multiple lines matching your line above, separated by blank lines, then issue this command...

sed -e "s/test/ohiotest/g" foo

Open in new window


I get the each transformation of test -> ohiotest, as expected.

Be sure to escape any "." characters, as "." matches any character + "\." only matches dot characters.

You don't show your exact transformation, so I'm guessing you're passing non-escaped wildcard characters which are matching in places you don't expect.
0
 
petersystems engineerAuthor Commented:
Youre correct, this works great, thanks!
sed -e "s/test/ohiotest/g" /home/user/dir/bin/start_w_jmx.sh
0
 
petersystems engineerAuthor Commented:
I'm sorry to add, while the transformation works, the original file is unaltered.
0
 
arnoldCommented:
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
0
 
petersystems engineerAuthor Commented:
that works, thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.