如何使用PowerShell从文件中删除基于日期的行 [英] How to delete date-based lines from files using PowerShell

查看:236
本文介绍了如何使用PowerShell从文件中删除基于日期的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些CSV文件,我需要删除包含日期大于指定日期的所有行。

I have some CSV files where I need to delete all lines that contain a date that is greater than a specified date. How would I do this in PowerShell?

BTW:这是日期格式:09/29/2011

BTW: here is the date format: 09/29/2011

示例:我想删除包含大于09/29/2011的日期的所有行。

Example: I would want to delete all lines that contain the date greater than 09/29/2011.

推荐答案

 foreach ($file in gci *.csv){
   (gc $file) |
     ? {[datetime]$_.split('|')[1] -lt '09/29/2011'
     } | set-content $file

 }

假设是管道分隔文件。

这篇关于如何使用PowerShell从文件中删除基于日期的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆