Re: [MSH] Applying regular expression to whole file
- From: "James Truher [MSFT]" <jimtru@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 13 Oct 2005 10:33:57 -0700
another way to achieve this is using the join method on the string object
[string]::Join("`n",(get-content old.txt))
"Bruce Payette [MSFT]" <Bruce Payette [MSFT]@discussions.microsoft.com>
wrote in message news:44FB83CE-3380-47AC-AD34-3967BE1E9F13@xxxxxxxxxxxxxxxx
> So - here's a wierd little trick using a sort-of bug in out-string. The
> out-string cmdlet takes it's input and returns the result as a single
> string
> with newlines. This let's you do something like:
>
> (get-content old.txt | out-string) -replace "foo","bar" > new.txt
>
> -bruce
>
> "Jouko Kynsijärvi" wrote:
>
>> Jack Ukleja wrote:
>> > Is there an easy way to load an entire text file as a single string
>> > into a MSH variable? Perhaps there is some MSH syntax that does
>> > exactly what I want that ive missed?
>>
>> You can concatenate all lines with:
>> $text = "$(get-content test.txt)"
>>
>> Or if you want lines separated by CR&LF instead of spaces:
>> $OFS = "`r`n"
>> $text = "$(get-content test.txt)"
>>
>> Or the framework way:
>> $text = [IO.File]::ReadAll('test.txt')
>>
>>
>>
.
- Follow-Ups:
- Re: [MSH] Applying regular expression to whole file
- From: /\\/\\o\\/\\/
- Re: [MSH] Applying regular expression to whole file
- References:
- Re: [MSH] Applying regular expression to whole file
- From: Jouko Kynsijärvi
- Re: [MSH] Applying regular expression to whole file
- Prev by Date: Re: show Computer description
- Next by Date: Re: show Computer description
- Previous by thread: Re: [MSH] Applying regular expression to whole file
- Next by thread: Re: [MSH] Applying regular expression to whole file
- Index(es):
Relevant Pages
|