Adding Lines to text In Bulk
-
First of all, since English is not my native language, there may be spelling errors. I’m sorry for that.
I have approximately 300 txt files. I want to add the line I want to the 1st line of each of these files. How can I do this in bulk to 300 files?
For example, I want to add the word “testfiles” to the 1st line of txt files
normal file content
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txtthe file content I want
testfiles
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txtAdditionally, as you can see in the example above, the txt files contain the text 1mayis.txt. I want to change this file name to the name of the file it is in.
For example
File name: trial_007(228).txt
file content
test -host- 73test >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txt
test -host- teswordshere >> c:\ping\1mayis.txtthe file content I want
test -host- teswordshere >> c:\ping\deneme_007(228).txt
test -host- teswordshere >> c:\ping\deneme_007(228).txt
test -host- teswordshere >> c:\ping\deneme_007(228).txtReplace this part in each file with the original name of the file.
Is there a way to get this done?
-
@Cansu-Bal
If all you wanted to do was insertsome text(which is fixed, and doesn’t depend on any properties of the file) followed by a newline at the beginning of a file, you can do that using the Find/replace form,Find in filestab:
Find what:(?s)[^\r\n]*(\R)?.*
Replace with:some text(?1${1}:\r\n)${0}
Filter:*.txt(restrict to.txtfiles)
Directory: whatever directory you want to edit files in
In all subfolders: check if you want to edit all files in a directory’s tree, rather than just direct children of that directory.If you’re new to this kind of thing, let me emphasize that you should always Always ALWAYS backup your files before doing a bulk find/replace.
Note that if you run this on a file with no newlines, it will insert a
CRLFnewline (\r\nin regular expressions) aftersome text. Otherwise, it will use the first newline found in the file.If you want to do a find/replace operation on a file that uses the name of the file, you could use a plugin, but since you are doing this on a large number of files, this is a job for other tools, not for Notepad++.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login