22 Votes

Replace Text with first Line

Question by Mail Request | 2023-03-16 at 00:32

I have a large number of text files in which I want to replace some text or - in my case - a certain character with the content of the first line of the same text file.

The structure of all these text files is always as follows:

An ~ rarely comes alone, because multiple ~s are better.
There are many types of ~s.
For ~, an ~ of an ~ would be the following:

In the first line there is a text (typically a word) and in the rest of the file the character ~ should be replaced with this text.

So I want to get the following result for the example file shown:

An example rarely comes alone, because multiple examples are better.
There are many types for examples.
For example, an example of an example would be the following:

I have a four-digit number of these text files. Of course, I can't work with the normal search and replace function, since the text in the first line is always different. Opening each file individually would also be far too much work for me. Is there any way to automate this task?

2Best Answer2 Votes

You can easily perform this task with the TextConverter on any number of text files simultaneously by using references in the normal replace function of the application.

For this, you can use the following settings in the program:

  • Activate the option "Actions > Text > Replace"
  • In the text box "Search", type: ~
  • In the text box "Replace", type: %ref:line=1%
  • Additionally, the option "References" under "Actions > Options" must be activated

With these settings, the TextConverter will search for the text "~" and replace it in each file with the first line of the corresponding file. This works through the placeholder "%ref:line=1%", which stands for the content of the first line. If the replacement should be taken from another line, you can also replace the "1" in this placeholder with any other line number.

If you don't activate the option "Actions > Options > References", the text "%ref:line=1%" will remain as such. In this options section you can also find an overview over all other available references. In addition to individual or multiple lines also characters, words or entire file contents can be referenced, and it is also possible to edit the contents of the reference before inserting it. You can find out more about this in the tutorial about using references in the TextConverter.
2023-03-16 at 00:39

ReplyPositive Negative

Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.