0

This can modify all PRODUCT_BUNDLE_IDENTIFIER to abc. However, how can i modify for these two iOS identifier an watchOS identifier with a different values?

sed -i -e "s/PRODUCT_BUNDLE_IDENTIFIER =.*/PRODUCT_BUNDLE_IDENTIFIER" = abc;/g" text.txt

 {
   2D02E400000000001C7 /* iOS Identifier */ = {
        isa = XCBuildConfiguration;
        buildSettings = {
            PRODUCT_BUNDLE_IDENTIFIER = "com.iOS";
        
        };
        name = Debug;
    };
    2D02E000000000051C7 /* Apple Watch OS Identifier */ = {
        isa = XCBuildConfiguration;
        buildSettings = {
            PRODUCT_BUNDLE_IDENTIFIER = "com.watchOS";
        
        };
        name = Debug;
    };
}
wong john
  • 55
  • 4

1 Answers1

0

That would be a bit more involved. There might be only a way to do it only with sed, but this is the quick hack i could come up with:

id='2D02E400000000001C7'
repl='abc'

if grep -q "$id" file; then
  id_lineno=$(cat -n file | grep "$id" | awk '{ print $1 }')
  sed_lineno=$((id_lineno+3))
  sed -i "${sed_lineno}s/PRODUCT_BUNDLE_IDENTIFIER =.*/PRODUCT_BUNDLE_IDENTIFIER = ${repl};/" file
fi

It assumes the whitespace is exactly the same as shown in your code block

hyperupcall
  • 869
  • 10
  • 21