Community
    • Login

    Adding Lines to text In Bulk

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    adding linetxt filesbulk
    2 Posts 2 Posters 574 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Cansu BalC Offline
      Cansu Bal
      last edited by

      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.txt

      the 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.txt

      Additionally, 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.txt

      the 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).txt

      Replace this part in each file with the original name of the file.

      Is there a way to get this done?

      Mark OlsonM 1 Reply Last reply Reply Quote 0
      • Mark OlsonM Offline
        Mark Olson @Cansu Bal
        last edited by

        @Cansu-Bal
        If all you wanted to do was insert some 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 files tab:
        Find what: (?s)[^\r\n]*(\R)?.*
        Replace with: some text(?1${1}:\r\n)${0}
        Filter: *.txt (restrict to .txt files)
        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 CRLF newline (\r\n in regular expressions) after some 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++.

        1 Reply Last reply Reply Quote 5

        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
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors