- 帖子
- 1013
- 积分
- 1228
- 技术
- 14
- 捐助
- 0
- 注册时间
- 2019-2-20
|
本帖最后由 5i365 于 2022-1-15 20:47 编辑
想知道powershell能否合并符号条件的多行,
详细描述如下:
#开头的一行, 若其段前和段后有单独一个#字符的行, 则此三行合并为一行, 如图中的⑤
至少连续两行, #开头的行:
如果它们的前面和后面没有单独一个#字符的行, 则合并为一行, 如图中的①②③④
否则则不要合并, 如图中的⑥
至少连续两行, #开头, >结尾的段落: 不合并, 如图中的⑦
-------------------------------------------------------------------------
行合并的格式如下: [即:行与行相接的地方,删除# 留一个空格]
合并前:
# The first row contains the column names.
# This file is available at:
# /testData/sample.csv
合并后:
# The first row contains the column names. This file is available at: /testData/sample.csv
-------------------------------------------------------------------------
另外, 也想将上面合并后的行, 在其下面,再复制一份, 即克隆行
规律就是这些, 感觉有点复杂, 请求高手支招, 非常感谢
示例文本:
Add-Type -Path "C:\chilkat.dll"
# This example program loads a file (sample.csv)
# that contains this content:
#
# year,color,country,food
# 2001,red,France,cheese
# 2005,blue,"United States",hamburger
# 2008,green,Italy,pasta
# 1998,orange,Japan,sushi
#
# The first row contains the column names.
# This file is available at:
# /testData/sample.csv
$csv = New-Object Chilkat.Csv
# Prior to loading the CSV file, indicate that the 1st row
# should be treated as column names:
$csv.HasColumnNames = $true
# We have the following XML.
# Copy this XML into the online tool at Generate Parsing Code from XML
# as a starting point for accessing the data..
# <?xml version="1.0" encoding="utf-8"?>
# <root>
# <html>
# <head>
# <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
# </head>
# <body text="#000000" bgcolor="#FFFFFF">
# <div>
# </div>
# </body>
# </html>
# </root>
#
# This is the code generated by the online tool:
#
$xml = New-Object Chilkat.Xml |
|