I'm trying to find all files that contains lines that start with a specific string, and then set everything in that line after that to lowercase. I'm able to do parts of what I want but can't seem to figure out how to get it all to work.
Here's an example of the string I'm looking for:
_assetBundleName: SomeDirectory/ChildDirectory
and I need it to be:
_assetBundleName: somedirectory/childdirectory
So I can't convert the entire line to lower case, just everything after the string I'm looking for (which is _assetBundleName:
). And I need to perform this on many files (all directories and subdirectories from where the command is run).
sed 's/[a-z]/\L&/g'
converts everything to lowercase, not just everything after the string I've found.
You can use this gnu-sed
with 2 capture groups:
sed -E 's/(_assetBundleName:)(.*)/\1\L\2/' file
\L\2
will lowercase only the 2nd capture group content.
As noted above that this requires gnu-sed
. If you don't have that then you can use this awk
command:
awk 'BEGIN {FS=OFS=":"}
$1 ~ /_assetBundleName/ {$2 = tolower($2)} 1' file