Combining multiple .txt files and sending to outlook

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

  • @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.

  • 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

  • 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

Log in to reply