简体   繁体   中英

Windows batch: append string to stdout

I am running several piped commands to get output files that looks like the following:

decode.exe < itch-20150213.txt | select -I 101 | dump.exe > 20150213.txt

Output text file:

val11 val12 val13 val14 
val21 val22 val23 val24 
... etc

Is there a simple way for me to append the string (date) "20150213" to the last column of the output so that I get:

val11 val12 val13 val14 20150213
val21 val22 val23 val24 20150213
... etc

(if it is absolutely impossible to do this simply in the windows command line, what would be the Bash method?) Thank you

There are no native batch tools or utilities that can do this conveniently. A pure batch file could be written, but it would ugly, and fairly slow. I'm sure you could find a Windows port of a unix tool that could do the job. Or you could write a simple custom JScript or VBS script. I also imagine it would be easy to do using PowerShell.

I would use my JREPL.BAT utility - a hybrid JScript/batch script that performs regular expression find and replace on stdin. JREPL.BAT is pure script that runs natively on any Windows machine from XP onward.

Assuming JREPL.BAT is somewhere within your PATH, then all you need is one more pipe to JREPL:

decode.exe < itch-20150213.txt | select -I 101 | dump.exe | jrepl $ " 20150213" > 20150213.txt

It would be just as easy to add the string as a prefix instead:

decode.exe < itch-20150213.txt | select -I 101 | dump.exe | jrepl "^" "20150213: " > 20150213.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM