would this do what you want?
- name: edit a line in a file
ansible.builtin.command:
chdir: /home/username/
cmd: 'sed -i "s/This is a file/This is a new file/" somefile'
> On 07/27/2023 3:13 PM CEST Kathy L <[email protected]> wrote:
>
>
> I am trying to edit a string in a multi-line file. For instance, if I had
> this string:
>
> This is a file and I am editing it
>
> I want to add the string "new" in front of file if it does not exist already.
>
> I've tried lineinfile, but the issue is that I don't know what else is on the
> line. There could be more data after "This is a file and I am editing it"
> that I don't want to change. What is the best way to do this?
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> mailto:[email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com
>
> https://groups.google.com/d/msgid/ansible-project/9c8e2dcf-ab7d-4984-ac0a-83e818699135n%40googlegroups.com?utm_medium=email&utm_source=footer.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/910865649.311112.1690466922457%40office.mailbox.org.