开发者

powershell - remove first 3 lines and last 4 from each file

Hallo guys. I'm trying to remove first 3 lines and last 4 from all the files within the folder. Moreover some lines contains leading spaces that I want to remove.

This is what I've done:

gci c:/my_folder/ | % {
$path = $_.fullname
$file = gc $_
$file[3..($file.length-4)] | % {$_.trimstart()} | out-file $path
} 

I can't under开发者_StackOverflowstand why at the end of the script ALL the files contain the same text. It seems that my variables don't change values within the script. Thanks for any help.


As I supposed I was looping always the same file. I needed to modify

$file = gc $_

in

$file = gc $_.fullname

Now everything works fine. Thanks the same :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜