Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - new line in text file with out-file

Reply
 
Old 06-20-2007   #1 (permalink)
Did
Guest


 
 

new line in text file with out-file

Hi,

$server = "server1"
$event = "event1"
$ip = "100.10.100.1"

I want to see in file text file:

server1
event1
100.10.100.1

So I tryed to create var and use it with out-host like this

$to_file = "`n$server + `n$event + `n$ip"
out- file -filepath c:\log1.log -append -inputobject $to_file

It's doesn't working.
Please help.

Didi


My System SpecsSystem Spec
Old 06-20-2007   #2 (permalink)
Hal Rottenberg
Guest


 
 

Re: new line in text file with out-file

On Jun 20, 6:50 am, Did <didi10...@walla.co.il> wrote:
> I want to see in file text file:
>
> server1
> event1
> 100.10.100.1


Try this:

$out = @"
$server
$event
$ip
"@

example:

40# $server = "my server" ; $event = "test event" ; $ip = "10.2.1.11"
41# $out=@"
>> $server
>> $event
>> $ip
>> "@
>>

42# $out
my server
test event
10.2.1.11

My System SpecsSystem Spec
Old 06-20-2007   #3 (permalink)
Jacques Barathon [MS]
Guest


 
 

Re: new line in text file with out-file

"Did" <didi10000@walla.co.il> wrote in message
news:1182336636.168062.115650@m36g2000hse.googlegroups.com...
> Hi,
>
> $server = "server1"
> $event = "event1"
> $ip = "100.10.100.1"
>
> I want to see in file text file:
>
> server1
> event1
> 100.10.100.1
>
> So I tryed to create var and use it with out-host like this
>
> $to_file = "`n$server + `n$event + `n$ip"


You are not doing the concatenation right. You are enclosing the variables
with double quotes which will automatically concatenate them for you, so you
do not need to concatenate them with a + sign. This should work:

$to_file = "$server`n$event`n$ip"

In addition, I think there is a bug with "`n" being doubled in some
circumstances. E.g. if you start or finish your string with a "`n" it will
show as two blank lines. In your case, if you want to have an empty line
before your text you can work around it like this:

$to_file = " `n$server`n$event`n$ip"

Note the space before the first "`n"... And finally, if you really do need
an *empty* line, you can follow the space with the backspace character which
will delete it (as if you had pressed Backspace on your keyboard):

$to_file = " `b`n$server`n$event`n$ip"

Hope that helps :-)

Jacques

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Unable to Create New Line in Text File PowerShell
How to read the LAST NON-BLANK line from a text file? VB Script
Read a line from a text file, without loading the entire file inmemory PowerShell
How to remove blanks line from a text outpu file PowerShell
The next line in a text file PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46