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}" *.* > FileOfFilesThat 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 == 5means. 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.txtso, 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
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