我试图解析使用的PostScript与Ghostscript的解释.txt文件。 .txt文件是我需要从中提取日期戳记的各种日志文件。文件中会有一行如“date:[01-May-2011 06:41:52]”。我试图简单地输出“01-May-2011 06:41:52”部分(没有括号等)到PDF。Postscipt:读取文件,写入PDF
我的PostScript代码:
/grabdate {
linehold ([) search { pop pop % get everything after brackets
(]) search {exch pop exch pop % get everything before brackets
== flush
} {pop} ifelse
} {pop} ifelse
} def
/strrx 256 string def % temp line stash
/filename (C:\\path\\to\\file.txt) def
filename (r) file /myworkfile exch def % name of opened file
{myworkfile strrx readline {/linehold exch store grabdate}
{myworkfile closefile exit} ifelse
} loop
在命令提示符下使用的Ghostscript我发出命令:
gswin32c \
-q \
-dNOPAUSE \
-dBATCH \
-sOutputFile=out.pdf \
-sDEVICE=pdfwrite myfile.ps
的PostScript代码部分的工作,因为它输出的正确解析“日期”行到标准输出(因为== flush
),但我的问题是,我似乎无法得到“grabdate”操作将相同的“日期”字符串写入PDF,而不是标准输出。是否有一组PostScript命令可用于执行此操作?我在这里错过了什么?
任何帮助表示赞赏。