[英]Parse string in Powershell and create a table
I have a variable in Powershell that return the following string我在 Powershell 中有一个变量返回以下字符串
S: Title = test S: Title = test2 S: Title = test3 S: Title = test4
TE: 2019-01-19T00:00:00Z TE: 2019-01-20T00:00:00Z TE: 2019-01-22T00:00:00Z TE: 2019-01-23T00:00:00Z
I'm trying to format this string to have something like (even in a csv file):我正在尝试将此字符串格式化为类似(即使在 csv 文件中):
test test2 test3 test4
2019-01-19 2019-01-20 2019-01-22 2019-01-23
but without success.但没有成功。 How can I do this?
我怎样才能做到这一点?
Edit: This is the line that generate the string.编辑:这是生成字符串的行。 Basically I want to extract Name and Expiration date of all the entries in a keepass database (I may have found another way using the xml file exported):
基本上我想提取keepass数据库中所有条目的名称和到期日期(我可能已经找到了使用导出的xml文件的另一种方法):
$entries = & "$kps" -c:ListEntries "$kdbx" -pw:$pass
I have to admit this is a bit excesive use of .replace()
but there isn't much to work with:我不得不承认这是
.replace()
过度使用,但没有太多可使用的:
$mystring= " S: Title = test S: Title = test2 S: Title = test3 S: Title = test4
TE: 2019-01-19T00:00:00Z TE: 2019-01-20T00:00:00Z TE: 2019-01-22T00:00:00Z TE: 2019-01-23T00:00:00Z "
$MyString.trim().replace(" S: Title = ",",").replace("T00:00:00Z TE: ",",").replace("TE: ","").replace("S: Title = ","").replace("T00:00:00Z","").replace(" ","") | convertfrom-csv
Output:输出:
test test2 test3 test4
---- ----- ----- -----
2019-01-19 2019-01-20 2019-01-22 2019-01-23
It would be easyer (and more overseeable) to implement those steps in the creation of the string.在创建字符串时实施这些步骤会更容易(也更容易监督)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.