vendredi 10 novembre 2017

Using gawk pattern, pipe etc. in cmd

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

Aucun commentaire:

Enregistrer un commentaire