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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.