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:
- copy needed .txt files to one folder
- combine file with “copy /b” command
- create pattern file with 1,2 and 5 row data inside
- filter out pattern using “findstr /g” command
- copy file content to outlook.
-
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.txtBut 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