Board logo

标题: [文本处理] [已解决]批处理如何删除文本2到5行和倒数1到9?谢谢 [打印本页]

作者: yyz219    时间: 2022-2-9 13:04     标题: [已解决]批处理如何删除文本2到5行和倒数1到9?谢谢

本帖最后由 yyz219 于 2022-2-9 15:44 编辑

删除文本2到5行(第5行为空行)和倒数1到9(第9行为空行),谢谢
++++++++++++++++++++++++++++++++++++++
问题解决了

#&cls&powershell -c "type '%~0'|out-string|iex"
$a=gc a.txt
$b=$a[1..4]+$a[-9..-1]
compare -ref $a -diff $b|select -expandproperty inputobject >a_new.txt
复制代码
作者: for_flr    时间: 2022-2-9 15:11

  1. #&cls&powershell -c "type '%~0'|out-string|iex"
  2. $a=gc a.txt
  3. $b=$a[1..4]+$a[-9..-1]
  4. compare -ref $a -diff $b|select -expandproperty inputobject >a_new.txt
复制代码

作者: yyz219    时间: 2022-2-9 15:39

回复 2# for_flr


    我试一试先 谢谢
作者: for_flr    时间: 2022-2-9 15:52

  1. [System.Collections.ArrayList]$a=gc a.txt
  2. $a.RemoveRange(1,5-2+1)
  3. $a.RemoveRange($a.count-9,9-1+1)
  4. sc a__.txt $a
复制代码
Powershell,增减、加减数组元素
RemoveRange(int index, int count)




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2