Find by regex and replace lowercase matching in Bash

I would like to replace the entire contents of the file that matches the given regular expression with their lower case. How:

grep -o '[^ ]*[AZ][^ ]*.png' file-21-05-2013.sql* | awk '{print tolower($0)}' 

The line above contains all lines in the specified file that have at least one uppercase character and print the lowercase equivalent.

I would like to replace the output of the grep command with the output of the entire command above

It makes sense?

+2
source share
2 answers

If you are using the GNU system, GNU sed has the following extension:

 \L Turn the replacement to lowercase until a \U or \E is found, 

The following command should do what you need:

 sed "s/\([^ ]*[AZ][^ ]*.png\)/\L\1/g" file-21-05-2013.sql* 
+2
source
 sed -nr '/^.*\b(\w*[AZ]\w*\.png).*$/{s//\1/;s/.*/\L\0/;p}' file 
+1
source

Source: https://habr.com/ru/post/945514/


All Articles