如何删除以“#"开头的行在CSV文件中 [英] How to delete lines that start with "#" in a CSV file

查看:213
本文介绍了如何删除以“#"开头的行在CSV文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每天早上我都有一个报告,该报告会生成一个CSV文件,其中包含计算机名称以及整个文件中的其他注释.注释的每一行都以#"开头,​​注释分散在整个文档中,而不仅仅是在文档的开头,因此我不能只阅读前几行.

Every morning I have a report that generates a CSV file that contains names of computers, as well as additional comments throughout the file. Each line that is a comment starts with "#", and comments are scattered throughout the document, not just at the start of the document so I can't just read over the first couple lines.

是否可以搜索CSV文件并删除以#"开头的行?还是有办法选择不以#"开头的行,并将其另存为新文件?

Is there any way to search through the CSV file and delete lines that start with "#"? Or is there a way to select lines that don't start with "#", and save them to as a new file?

推荐答案

是的,绝对可以.

您可以逐行读取文件,只需过滤掉以#开头的所有内容:

You could read the file, line by line, and simply filter out anything that starts with #:

Get-Content $csvPath |Where-Object {$_ -notlike '#*'} |Set-Content $newCsvPath

这篇关于如何删除以“#"开头的行在CSV文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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