mysql - 文本输出中隐藏空值的问题

标签 mysql powershell dhcp

我在尝试从 WINS 服务器中提取文本数据以创建以 S 和 6 个数字开头的计算机名称列表时,遇到了似乎隐藏空字符的问题。

输入数据类似于:S123456 [20h] DYNAMIC ACTIVE 1234567 UNIQUE 6/7/2014 ...

$output_file='D:\blah blah\workstations.txt'
$regex='\b[S]\d{6}\b'

Select-String -Path $input_path -Pattern "ACTIVE" |Select-Object Line | `
    Select-String -Pattern $regex -Allmatches|%{$_.Matches}|%{$_.Value -replace "`r|`n",""}|    get-unique > $output_file

当我尝试加载到 MySQL 表时,我得到 S null 1 null 2 null ...我如何去除或避免空值?

最佳答案

这是基于上面评论序列的答案。您可以设置输出文本文件的编码。大多数写入文本文件的内置 PowerShell 命令都接受 -Encoding 参数来实现此目的。所以改变

> $output_file

| Set-Content -Path $output_file -Encoding UTF8

将按照您指定的方式设置文件编码。

关于mysql - 文本输出中隐藏空值的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24002929/

相关文章:

java - java中Mysql的用法,while(result.next())与if和else

c# - 在 C# .NET 项目中启动时如何等待提升的 PowerShell 进程退出?

powershell - 具有参数/参数的Powershell

c++ - GNU/Linux : getting value of option 15 of DHCP without using `getnameinfo`

python解压缓冲区数据

php - AJAX 调用后 jQuery 未重定向

mysql - 给出所有不教数学的老师的名字

MySQL - 使一对值唯一

windows - 使用 PowerShell 设置 DNS

nginx - Kubernetes MetalLB 外部 IP 无法访问