|
|
||||||
|
#1
|
|
|
|
|
I would like to create a hashtable with the result from a pipe.
The mission is to read a file and create a hashtable with a linenumber. Like lnum line 1 something 2 some other stuff 3 even more.... .... ... I tried with $lines = gc "c:\test.txt" | &{$a=0}{$a++; @{lnum=$a; $line=$_} } but $lines is empty. What is the trick here? thanks, |
|
|
|
#2
|
|
|
|
|
"gurbao" <audunj> wrote in message
news:9370 > > I would like to create a hashtable with the result from a pipe. > The mission is to read a file and create a hashtable with a > linenumber. > > Like > > lnum line > 1 something > 2 some other stuff > 3 even more.... > ... ... > > I tried with > $lines = gc "c:\test.txt" | &{$a=0}{$a++; @{lnum=$a; $line=$_} } > > but $lines is empty. > > What is the trick here? Try this: 685# $lines = gc "c:\test.txt" | %{$ht=@{};$a=1}{$ht[$a++] = $_}{$ht} In a hash table you can't really rename the Name/Value properties and I think you want the line info to be in the same hashtable. In your approach, you're creating a new hashtable for every line of the file. |
|
#3
|
|
|
|
|
On May 16, 5:39 pm, gurbao <aud> wrote:
[..] > ... ... > > I tried with > $lines = gc "c:\test.txt" | &{$a=0}{$a++; @{lnum=$a; $line=$_} } > > but $lines is empty. > > What is the trick here? > > thanks, 1# function file2hashtable { begin { $h = @{}; $i=0 } process { $h.add($i++, $_) } end { $h } } 2# $ht = (gc file.txt | file2hashtable) - Oisin |
|
|
| Similar Threads | |
| Error when Creating Pipeline Hello, I'm trying to create a receive pipeline. When I try to select a document schema in the XML disassembler pipeline component I get the error message "The system cannot... |
|
| Creating a hashtable dynamically Can I create a hashtable dynamically? I'm wanting to do something like $files=@{} $files+=gci|%{$_.name="$_.size"} I'd like to end up with something... |
|
| Help creating a pipeline object Hi, I am trying to create an instance of a BizTalk Pipeline object from within a ..net method. The code would be something like... |
|
| creating a custom pipeline Hi, If i need to create the custom pipeline, wat are all the steps i need to do. Is there any articles or some resources available there. thanks, Shoukat. |
|
| creating custom pipeline I am trying to do the following. When a data file is dropped in folder, i want to write out a XML file that contains the incoming dat file name. I do not care about the... |
|
|
All times are GMT. The time now is 12:03 PM. | Privacy Policy
|