[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] PowerShell脚本-split 多个列

iidwma哥哥   如果是split列数同时增加支持多个列
那么是这样写吗?  偿写不同写法, 但似乎都不对

$b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[5][6]

$b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[5,6]

  1. #@&cls&powershell "type %~s0|out-string|iex"&exit
  2. $a=gc -readcount 0 D:\UTF16.txt
  3. $b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[5,6] -jion '|'
  4. $f=0
  5. sc D:\out.txt $(foreach($i in $a){if(($f -eq 0) -and $i -match "简名:.*?($b)"){$i;$f=1}elseif(($f -eq 1) -and $i -match '已执行'){$f=0;$i,''}elseif($f -eq 1){$i}})
复制代码

TOP

本帖最后由 娜美 于 2023-7-22 18:25 编辑

回复 2# idwma
  1. #@&cls&powershell "type %~s0|out-string|iex"&pause
  2. $a=gc -readcount 0 UTF16.txt
  3. $b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[6,7] -jion '|'
  4. $f=0
  5. sc out.txt $(foreach($i in $a){if(($f -eq 0) -and $i -match "简名:.*?($b)"){$i;$f=1}elseif(($f -eq 1) -and $i -match '已执行'){$f=0;$i,''}elseif($f -eq 1){$i}})
  6. start out.txt
复制代码
仔细试了几次   返回了一些信息
  1. iex : 所在位置 行:3 字符: 53
  2. + $b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[6,7] -jion '|'
  3. +                                                     ~~~~~
  4. 表达式或语句中包含意外的标记“-jion”。
  5. 所在位置 行:3 字符: 59
  6. + $b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[6,7] -jion '|'
  7. +                                                           ~~~
  8. 表达式或语句中包含意外的标记“'|'”。
  9. 所在位置 行:1 字符: 53
  10. +                                                     ~~~
  11.     + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
  12.     + FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
复制代码

TOP

错了是-join

TOP

本帖最后由 娜美 于 2023-7-23 13:51 编辑

回复 4# idwma

idwma哥哥 差不多对了

我偿试很多
但如果第7列没有 ( 这个符号  则正常
  1. #@&cls&powershell "type %~s0|out-string|iex"&exit
  2. $a=gc -readcount 0 UFT16.txt
  3. $b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[6,7]
  4. $f=0
  5. sc out.txt $(foreach($i in $a){if(($f -eq 0) -and $i -match ".*$b"){$i;$f=1}elseif(($f -eq 1) -and $i -match '已执行'){$f=0;$i,''}elseif($f -eq 1){$i}})
  6. start out.txt
复制代码
第7列刚好有 ( 这个符号      
如果有 ( 这个符号  不正常了  输出结果为空   似乎不能匹配 (  这个符号

-match ".*$b"    这里是否需要修改适应  ( 这个符号呢

TOP

  1. #@&cls&powershell "type %~s0|out-string|iex"&exit
  2. $a=gc -readcount 0 UFT16.txt
  3. $b=(($a[-1..-500] -match '企业 ')[0] -split ' ')[6,7] -join ' '
  4. $f=0
  5. sc out.txt $(foreach($i in $a){if(($f -eq 0) -and $i -match ".*$([regex]::escape($b))"){$i;$f=1}elseif(($f -eq 1) -and $i -match '已执行'){$f=0;$i,''}elseif($f -eq 1){$i}})
  6. start out.txt
复制代码

TOP

本帖最后由 娜美 于 2023-7-23 13:53 编辑

回复 6# idwma


    嗯这个可以  今天细测正确,      

谢谢 idwma哥

TOP

返回列表