Solved

Powershell add text to a specific line in txt file

Posted on 2014-02-12
3
4,814 Views
Last Modified: 2014-02-12
Hi!

I have a text file. I need to add some text at line 10 of this file. Line 10 is empty, so 'replace' is not an option.

Can it be done using powershell?
0
Comment
Question by:SvenIA
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39853041
$data = get-content c:\test\file.txt
$data[9]="some text here"
$data | out-file c:\test\file.txt
0
 
LVL 7

Author Comment

by:SvenIA
ID: 39853312
Thanks, but with this code i cannot add text on an empty line, only overwrite the text on the previous line.

Array assignment failed because index '10' was out of range.
0
 
LVL 7

Author Closing Comment

by:SvenIA
ID: 39853327
It does seem to work now. Don't know why it didn't just before. Thanks a lot!
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Set OWA language and time zone in Exchange for individuals, all users or per database.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now