0

I have a CSV file with about 10 columns separated with a ; (semicolon). I would like to add another column which generates a hashkey for the first columns value.

Is there a possibility in Powershell to do this? Also are there short haskeys (up to 10 to 15 chars)?

Example:

Old:

10000;value2;value3....

New:

HashkeyOf10000;1000;value2;value3...

arco444
  • 22,002
  • 12
  • 63
  • 67
user2428207
  • 825
  • 4
  • 16
  • 29
  • `Also are there short hashkeys (up to 10 to 15 chars)` <-- What does this mean? – arco444 Jan 05 '15 at 14:57
  • For example MD5 is 35 chars long. Just wanted to know if there are any shorter ones. – user2428207 Jan 05 '15 at 14:59
  • Looking at this [answer](http://stackoverflow.com/questions/4567089/hash-function-that-produces-short-hashes)(in Python but logic should be the same)they just truncated the result. It allows for possible issues but they should be few and far between. – Matt Jan 05 '15 at 15:56
  • Also read this discussion on the topic: http://programmers.stackexchange.com/questions/250235/whats-the-shortest-generating-one-way-hash-algorithm which says that it cant really be done. – Matt Jan 05 '15 at 15:59

1 Answers1

0

You can use a calculated property for adding a column to a CSV:

$csv = 'C:\path\to\your.csv'

(Import-Csv $csv -Delimiter ';') |
  select -Property @{n='Hashkey';e={Calc-Hash $_.A}},* |
  Export-Csv $csv -Delimiter ';' -NoType

Replace Calc-Hash with the actual name of your hash function and A with the actual name of the first column of your CSV.

The parentheses around Import-Csv are required to ensure that reading the file is completed before writing the output starts.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328