C
C
cptedward_kenway2021-06-30 16:46:29
linux
cptedward_kenway, 2021-06-30 16:46:29

Enumerating and modifying files with a bash script?

Good afternoon.
There is a need to enumerate files (* .ini) in the directory with a bash script and add a certain line there. There is some text in the file, and also in some files there is a line that needs to be commented out, for example: Notify="notify/11111"
I have zero experience in bash scripts.
As I understand it, this can be done through a nested loop, but I did not think of how to do it.

All that was enough for me was just outputting files in a directory :)
find . -name "*.ini"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor Taran, 2021-06-30
@cptedward_kenway

find . -regex ".*\.\ini" -exec sed -i 's/было/стало/g' "{}" \;

S
Saboteur, 2021-06-30
@saboteur_kiev

if the files are in the same directory, then
sed -i 's/было/стало/g' /home/user/mydir/*.ini
comment the line:

sed -i 's/Notify="notify/11111"/#Notify="notify/11111"/g' /home/user/mydir/*.ini

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question