1

I have multiple files and I need to print out pattern from multiple files, add some text between and at the end of the lines and send output text to outlook or just create new text file.

I am able to use pattern separately but not able to link everything using pipe. I receive blank file when using |. So I am creating extra file and use this as reference.

Input files look like (lets say 20 files):

File name: xxx
Description: xxx

date & time etc.

\\dir\documents\file.pdf (link)

A: info1
B: info2
C: info3
D: info4

I would like the output file/data look like this:

File name: xxx
Description: xxx
Linked documents: - added text
\\dir\documents\file.pdf

date &time

A: info1
B: info2
C: info3
D: info4
----------------------------------------
File name: xxx
Description: xxx
Linked documents: - added text
\\dir\documents\file.pdf

date &time

A: info1
B: info2
C: info3
D: info4

This part of code is working:

cd C:\Users\xxx\Desktop\\Files
dir
gawk "/File|Description|dir/" *.* > data.txt 

And also this part is working

gawk "/Description/ {print;print \"Linked Documents:\";next}1" *.* > data.txt

But I am not able to use pipe like that:

gawk "/File|Description|dir/" | gawk "/Description/ {print;print \"Linked Documents:\";next}1" *.* > data.txt

My code so far looks like that:

cd C:\Users\xxx\Desktop\Files
dir
gawk "/Part|Description|dir/" *.* > C:\Users\xxx\Desktop\File\Temp\data.txt
cd C:\Users\xxx\Desktop\File\Temp
dir
gawk "/Description/ {print;print \"Linked Documents:\";next}1" *.* > C:\Users\xxx\Desktop\File\output.txt
del C:\Users\xxx\Desktop\File\Temp\data.txt
@echo off
clip < "C:\Users\xxx\Desktop\File\output.txt"

Output file looks like:

File name: xxx
Description: xxx
Linked documents:
\\dir\documents\file.pdf
File name: xxx
Description: xxx
Linked documents:
\\dir\documents\file.pdf

Any tips how to combine code so I don´t have to create extra .txt files Why | not working - am I doing something wrong? I use win10 cmd

Thank you in advance

Juri
  • 11
  • 1
  • Replace in search string each `\"` by `\x22`. For an explanation see [cmd - sed command input parse error](https://stackoverflow.com/a/46639831/3074564). – Mofi Nov 10 '17 at 11:46
  • And on command line with output of first `gawk` redirected as input to second `gawk` the argument `*.*` must be before `| gawk` and not as second argument of second `gawk` as otherwise the first `gawk` runs the search on __stdin__ input. – Mofi Nov 10 '17 at 11:52
  • `gawk` is not something that comes with Windows 10. Is this gawk from Cygwin or Msys? – lit Nov 10 '17 at 20:16
  • I think it was GnuWin and the version gawk-3.1.6-1 – Juri Nov 13 '17 at 07:30
  • Thank you Mofi. `*.*` before `| gawk` worked. – Juri Nov 13 '17 at 08:41

0 Answers0