使用 PowerShell 将选项卡写入文件 [英] Writing tabs to a file using PowerShell

查看:72
本文介绍了使用 PowerShell 将选项卡写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 PowerShell 中回显数组的一系列元素,但在元素之间提供各种分隔符,所以我使用了;

I need to echo a series of elements of an array in PowerShell, but provide various delimiters between the elements, so I'm using;

    Add-Content -Path $tempInputDir\testoutput.log -value ($($fields[0]) + "   "+
        $($fields[1])  + "    " + $($fields[2]) + " " + $($fields[3])    + "    "+
        $($fields[15]) + "    " + $($fields[17]))
}

我需要能够添加制表符和空格字符,正如您从上面的代码中看到的,我刚刚通过在双引号之间物理添加制表符和空格来完成此操作,但我确定这会导致问题线.

I need to be able to add tabs and space characters, as you can see from the code above I've just done this by physically adding tabs and spaces in between double quotes, but I'm sure this will cause problems down the line.

将这些字符回显到文件的正确方法是什么?我在某处读到可以使用't",但这似乎不起作用?

What's the correct way to echo these characters to a file? I read somewhere that "'t" could be used, but that doesn't seem to work?

推荐答案

您可以将 `t 用于双引号字符串中的制表符.您还可以将上述内容简化为:

You can use `t for a tab character in a double quoted string. You can also simplify the above to:

"$($fields[0])   $($fields[1])   $($fields[2]) $($fields[3])  $($fields[15])  $($fields[17])" | Add-Content $tempInputDir\testoutput.log

这篇关于使用 PowerShell 将选项卡写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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