How to insert text after a certain string in file using run script in iOS

549 views Asked by At

We are trying to update the file using run scripts. We are using the command

 sed -i '/use_frameworks/a  HelloPod1'  ../Podfile

and building the application then we are getting error link this

sed: 1: "../Podfile": invalid command code . Command /bin/sh failed with exit code 1

If we try to run the command from terminal its working fine.

sed command won't work in Xcode run scripts ? How can we insert the new lines in file ?

1

There are 1 answers

0
anishsane On

sed on iOs expects a backup file suffix after -i option. Even when you think you haven't provided it, it will take next argument as suffix.

So, it takes /use_frameworks/a HelloPod1 as suffix and ../Podfile as sed command. ../Podfile is not a valid sed command, which causes the error.

This should work:

sed -i.bak '/use_frameworks/a HelloPod1' ../Podfile

Now, it takes .bak as backup suffix, /use_frameworks/a HelloPod1 as sed command and ../Podfile as the file to operate on.