1

Trying to change name="Android" to name="Android1", name="Android2" and so on..

Will need to run my python script using the command line on windows, macOS and Linux.

Output2.xml

<?xml version="1.0" encoding="UTF-8"?> 
    <robot generator="Robot 2.9 (Python 3.6.8 on linux)" generated="20190701 08:47:35.439"> 
    <suite id="s1" name="Android" source="/FILEPATHHERE">
    #ommitted unrelevant lines from xml file

Problem

I have tried a couple of ways listed on Stackoverflow but realized that it is not as easy as it seems.

Was just trying the ways using my mac terminal and when I tried running this:

sed -i 's/android/newtext' output2.xml 

Error: sed: 1: "output2.xml": invalid command code o

Added in '' but another new error came up:

sed -i '' 's/android/newtext' output2.xml

Error: sed: 1: "s/android/newtext": unterminated substitute in regular expression

Can I use sed commands? Seems like I am doing it wrong as I have some issues in editing XML using sed commands.

Main References

https://askubuntu.com/questions/20414/find-and-replace-text-within-a-file-using-commands https://superuser.com/questions/916665/edit-xml-file-using-shell-script-command

1 Answer 1

1

You have to give an end separator for the replace pattern, btw, since you specify the -i flag for the backup file, it shouldn't be a zero-length extension for that, at least for macOS, check the man page about it.

sed -i 'new' 's/android/newtext/' output2.xml
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.