Append to text file
Apache 2.0Appends or replaces content of an existing plain text file, or creates a new one if it doesn't already exist. Please note that this recipes requires existing plain text files' format to be successfully parsable by OpenRewrite. If a file is left unchanged, it might be parsed as a Quark rather than plain text. In such case, use the plainTextMask option. See the Gradle or Maven plugin configuration page.
org. openrewrite. text. AppendToTextFileRequired
File name, using a relative path. May also be a glob expression (e.g. **/*.txt) to match one or more existing files; when a glob is supplied no new file is created. If a non-plaintext file matches, that file is left unchanged.
Multiline text content to be appended to the file.
Optional
If a new file is created, this content will be included at the beginning.
Print a newline automatically after the content (and preamble). Default true.
Determines behavior if a file exists at this location prior to Rewrite execution.
Continue: append new content to existing file contents. If existing file is not plaintext, recipe does nothing.Replace: remove existing content from file.Leave: (default) do nothing. Existing file is fully preserved.Merge: append only lines from new content that are not already present in the file. Lines are compared line-by-line after trimming whitespace. Preserves existing line order.
Note: this only affects the first interaction with the specified file per Rewrite execution. Subsequent instances of this recipe in the same Rewrite execution will always append.
mod run . --recipe= org. openrewrite. text. AppendToTextFile \
-P relativeFileName= foo/ bar/ baz. txt \
-P content= 'Some text. 'Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.