我需要对CSV文件中的数据列进行哈希处理(模糊处理).首选脚本 [英] I need to hash (obfuscate) a column of data in a CSV file. Script preferred

查看:116
本文介绍了我需要对CSV文件中的数据列进行哈希处理(模糊处理).首选脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以竖线分隔的文本文件,其中包含标题行. (我在问题中说CSV是为了使其更容易理解...我想大多数解决方案都适用于这两种格式.)

I have a pipe-delimited text file with a header row. (I said CSV in the question to make it a a bit more immediately understandable ... I imagine most solutions would be applicable to either format.)

文件如下:

COLUMN1|COLUMN2|COLUMN3|COLUMN4|...|
Field1|Field2|Field3|Field4|...|
...

我需要遮盖(例如)第3列和第9列中的数据,而又不影响文件中的其他任何条目.

I need to obscure the data in (for example) columns 3 and 9, without affecting any of the other entries in the file.

我想使用SHA1或MD5之类的哈希算法来做到这一点,以便在遇到任何地方相同的字符串都可以解析为相同的哈希值.

I want to do this using a hashing algorithm like SHA1 or MD5, so that the same strings will resove to the same hash values anywhere they are encountered.

编辑-我为什么要这样做
我需要向第三方发送一些数据,并且某些列包含敏感信息(例如客户名称).我需要文件完整,并且在替换字符串的地方,每次遇到文件时都需要以相同的方式进行操作(以便保留任何映射或分组).它不需要军事加密,只是很难逆转.由于我需要间歇性地执行此操作,因此脚本化的解决方案将是理想的选择.
/EDIT

EDIT - Why I want to do this
I need to send some data to a third party, and certain columns contain sensitive information (e.g. customer names). I need the file to be complete, and where a string is replaced, I need it to be done in the same way every time it is encountered (so that any mapping or grouping remains). It does not need military encryption, just to be difficult to reverse. As I need to to this intermittently, a scripted solution would be ideal.
/EDIT

使用命令行工具或脚本实现此目的最简单的方法是什么?

What is the easiest way to achieve this using a command line tool or script?

我希望使用批处理脚本或PowerShell脚本,因为不需要任何其他软件即可实现...

By preference, I would like a batch script or PowerShell script, since that does not require any additional software to achieve...

推荐答案

尝试

(Import-Csv .\my.csv -delimiter '|' ) | ForEach-Object{     
    $_.column3 = $_.column3.gethashcode()
    $_.column4 = $_.column4.gethashcode()
    $_    
} | Export-Csv .\myobfuscated.csv -NoTypeInformation -delimiter '|'

这篇关于我需要对CSV文件中的数据列进行哈希处理(模糊处理).首选脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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