In the top you reference a file name file.txt
, but then only deal with files of the name config.yml
, so I assume it's config.yml
that contains these patterns.
The locate
and bash
tags are kinda misleading, as this has nothing to do with both of those :) More importantly, what kind of environment is this? On Linux systems, GNU/sed is commonly installed and needs the -E
option to understand the swipe|pinch
condition. Bracket expressions (the [0-9]
part of your pattern) works even without -E
.
So, with that being considered, the following works with GNU/sed and BSD/sed:
locate config.yml | while read -r i; do sed -E '/swipe|pinch/s/[0-9]/3/' "$i"; done
Or, with find
:
find . -name config.yml -exec sed -E '/swipe|pinch/s/[0-9]/3/' '{}' +
NB: your pattern /swipe|pinch/
was correct, the suggestion to change it to escape the pipe symbol to /swipe\|pinch/
will not work as now it's no longer a regular expression and would match a literal |
and thus would not match any content of your file. However, it would work if the surrounding apostrophes ('
) are omitted:
sed -E /swipe\|pinch/s/[0-9]/3/
-n
in your-exec
-runsed
?man sed
: ` -n, --quiet, --silent suppress automatic printing of pattern space`|
to\|
or add option-E
, add option-i
if you want to edit in-place, remove-n
and you don't need to escape+
.sudo find / -name config.yml -exec sed -En '/swipe\|pinch/s/[0-9]/3/' '{}' \+
. I will add-i
once I would see it substitued correctly but for now, do not even substitued-n
, it suppresses any output. And you don't need to escape|
if you use-E
.