Community
    • Login

    Combining multiple .txt files and sending to outlook

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    filtercombine
    4 Posts 2 Posters 1.6k Views
    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.
    • Jüri OleitšukJ
      Jüri Oleitšuk
      last edited by

      Looking a way to filter out row 1,2 and 5 from multiple selected .txt files and send the content to outlook. Is it possible in notepad++?

      At the moment:

      1. copy needed .txt files to one folder
      2. combine file with “copy /b” command
      3. create pattern file with 1,2 and 5 row data inside
      4. filter out pattern using “findstr /g” command
      5. copy file content to outlook.
      1 Reply Last reply Reply Quote 0
      • Jim DaileyJ
        Jim Dailey
        last edited by Jim Dailey

        @Jüri-Oleitšuk

        If you put all the files (alone) in a directory, then you could use gawk (GNU’s version of AWK) like this:

        gawk "FNR != 1 && FNR != 2 && FNR != 5{print}" *.* > FileOfFiles
        

        That would create a file named FileOfFiles that would contain the contents of all the files in the directory except for lines 1, 2, and 5.

        1 Reply Last reply Reply Quote 2
        • Jüri OleitšukJ
          Jüri Oleitšuk
          last edited by

          Thanks for gawk tip.

          What if I would like to print out 1,2 and 5th line, or print out line starting with “name”

          Printing out only one line seems working:
          gawk “FNR == 1{print}” . > FileOfFiles.txt

          But printing out multiple lines does not work - getting empty file:
          gawk “FNR == 1 && FNR == 2 && FNR == 5{print}” . > FileOfFiles.txt

          1 Reply Last reply Reply Quote 0
          • Jim DaileyJ
            Jim Dailey
            last edited by Jim Dailey

            FNR is the line number of each file as the file is processed. It is not possible for FNR to be 1, 2, and 5 simultaneously! :-) That is what the condition you tried:

            FNR == 1 && FNR == 2 && FNR == 5
            

            means. That is why you saw no output.

            If you want to print lines 1, 2, and 5, then if FNR is 1 or 2 or 5, you want to print the line. That translates to:

            gawk "FNR==1 || FNR==2 || FNR==5{print}" *.* > FileOfFiles.txt
            

            so, you nearly had it.

            If you want to print the filename before the lines of each file, you can do that like this:

            gawk "FNR==1{print FILENAME} FNR==1 || FNR==2 || FNR==5{print}" *.* > FileOfFiles.txt
            
            1 Reply Last reply Reply Quote 1
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors