22 Votes

Remove arbitrary Text up to certain Word from Text File

Question by Mail Request | Last update on 2022-10-20 | Created on 2014-07-11

I have several text files, that have approximately the following structure:

Arbitrary text including arbitrary information
Author: arbitrary name
Any other random text

I would like to remove the "header" from those files. Everything before the word "Author" belongs to the header. The difficulty is that the information given in the header can differ and are not always the same, so that I cannot use the normal "Search and Replace" function.

After the replacement, my file should look like this:

Author: arbitrary name
Any other random text

How can I use the TextConverter tool to delete all characters and words from the start/beginning of a file up to a certain string?

3Best Answer3 Votes

Update: The TextConverter has been further developed since my old answer and now contains a function with which this task can be carried out directly without having to use regular expressions:

  1. Activate the action "Text > Trim"
  2. Underneath, activate the action "Remove all characters before a text"
  3. Into the text field, you write the text until which all characters should be deleted
  4. With the checkbox "Include text" you control whether you want to keep the search text at its place or the search text should also be deleted

Of course, also in the latest version of the TextConverter, my old answer retains its validity and you can continue to alternatively solve this task with the functions "replace with regular expressions" and "deletion of lines".

I have therefore attached my old answer, in which I have explained those steps, under this answer:
2022-10-20 at 23:33

ReplyPositive Negative
11 Vote

Old Answer (still valid):

This task can be done in the TextConverter, for example with using regular expressions.

  1. Activate the option "Actions > Text > Replace"
  2. Activate the option "Interpret as Regular Expression"
  3. Search for: .*(Author.*)
  4. Replace with: $1

By replacing ".*(Author.*)" with "$1", you should get your desired result. The regular expression in the search box finds arbitrary characters up to the word "Author" and arbitrary characters after this word. The $1 in the replace box, replaces with the characters, that has been found in brackets - that is everything except the characters written before "Author".

Alternative: If your header should have a fixed number of lines, you can also use the function "Actions > Lines > Delete Lines". Here you can enter for example "1-3", "1,2" or "1" in the field "Delete Lines according to Line Numbers" (counted from the beginning) to remove the specified lines from the beginning of the text file.

PS: You should always have a look at the preview to ensure, that the result is as desired, before storing the file.
Last update on 2022-10-20 | Created on 2014-07-11

Positive Negative

Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

PHP: File Download Script

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.