Insert a newline after match in files of specific name under some subdirectories?

Hi

I'd like to add the newline:

\tuser: nobody ", or " <TAB>user: nobody

to all files named:

docker-compose.yml

in subfolders of pwd with names beginning with 10-20.

Within these files, I'd like to find the line (there'll only be one) containing:

command: celery worker

NOTE: As far as I know, each of these lines will actually contain:
command: celery worker -l info -A snakeeyes.blueprints.contact.tasks , but I haven't checked each file, some may differ so the above search pattern seemed reasonable.
And append on a new line directly below the matching line, the aforementioned string, either:

\tuser: nobody ", or " <TAB>user: nobody

If anyone knows how to do this, a (if possible, verbosely annotated) answer would be greatly appreciated!

--- Not Important:

I've been trying to figure this out by myself - I had been reading Sed & Awk by Dougherty & Robbins earlier this year, but I haven't gotten very far, and there's nothing in my notes for this sort of case... here's what I had come up with thus far after searching line and combining different things I read:

find . -name docker-compose.yml -exec sed -i "command: celery worker/ a\\\tuser: nobody" {} \;

Mostly including this not as a starting point, but so you can laugh at it (it mangled the files)

Try

find . -name docker-compose.yml -exec sed -i "/command: celery worker/ a\\\tuser: nobody" {} \;
1 Like

Thanks RudiC, that did it :o.

Turned out I needed spaces for YAML.

find . -name docker-compose.yml -exec sed -i "/command: celery worker/ a\ \ \ \ user: nobody" {} \;