powershell - Powershell:在txt文件的每2行插入一个换行符
问题描述
我必须将 powershell 中的数组中的值通过管道传输到 txt 文件,但问题是这些值在没有换行符的情况下输入到文本文件中,如下所示:
价值11 价值12 价值
21
价值
22
我希望它看起来像这样:
价值
11 价值 12
价值
21 价值 22
基本上在每两行之后用换行符分隔文本。如何使用 powershell 实现这一目标?
解决方案
用于Get-Content -ReadCount 2
一次读取文件 2 行,然后在每行之后注入一个空字符串,然后写入一个新文件:
Get-Content .\path\to\file.txt -ReadCount 2 |ForEach-Object {
$_ # This will expand to two lines at a time
'' # followed by this empty string
} |Set-Content .\path\to\output.txt
推荐阅读
- sql - 如何在 SQL 中计算学年?
- python - discord.py BS4 无法从 href 元素中获取信息
- python-3.x - Scrapy 在分页中提供了模棱两可的结果
- node.js - nodejs fs.WriteStream.write(chunk) “原子” wrt 异步事件是什么?
- react-native - React Native Expo:使用任务管理器在后台获取地理位置
- java - 如何并行调用多个Flowable语句?
- html - 当文件从另一个文件扩展时,不显示 .html 文件的内容
- c++ - 无法在 Ubuntu Conda 环境中编译 R 包:x86_64-conda-linux-gnu-c++:未找到
- python - 如何正确安装最新版本的 pygame?
- gekko - 使用 GEKKO 作为运动自行车模型不同控制算法的模拟器