0
  1. I want to find all occurrences of this:
[UIFont tly_primaryFontWithWeight:TVFontWeight300 size:14.0f]
  1. Parse whatever is after "size:" and before the closing square bracket. In this case it would be "14.0f".

  2. And then replace that occurence with this:

[UIFont tly_primaryFontWithSize:14.0f];

How can I do so?

thisiscrazy4
  • 1,905
  • 8
  • 35
  • 58
  • 1
    This is BashFAQ #21 ("How can I replace a string with another string in a variable, a stream, a file, or in all the files in a directory?"): http://mywiki.wooledge.org/BashFAQ/021 – Charles Duffy Sep 22 '14 at 23:49
  • 1
    Why do you need to parse the `14.0f`? You would likely be able to just match `tly_primaryFontWithWeight:TVFontWeight300 size:` and replace it with `tly_primaryFontWithSize:`. – lurker Sep 22 '14 at 23:52
  • http://stackoverflow.com/questions/16003706/how-can-i-recursively-replace-a-string-with-another-in-many-files-using-bash, http://stackoverflow.com/questions/7260802/recursively-traverse-directory-and-replace-function-calls and http://stackoverflow.com/questions/307796/how-do-i-replace-php3-with-php-inside-every-file-in-a-directory are among those (many) duplicates. – Charles Duffy Sep 22 '14 at 23:54
  • BTW, the one thing that makes this at all different from the first three duplicates I find searching SO is that you want to use a backreference. That's easily done, if you use GNU sed with the `-r` option for ERE; it might look like `size:([^]]+)\]` on the match side, and then you'd use `\1` in the replace side to refer to the matched content... but that's if you ignore lurker's (good) advice; follow that advice and the duplicates are exactly relevant as-is. – Charles Duffy Sep 22 '14 at 23:58
  • @lurker didn't think of it that way, good advice! – thisiscrazy4 Sep 23 '14 at 05:54

0 Answers0