Home » Infrastructure » Unix » file handling using perl
file handling using perl [message #153423] Mon, 02 January 2006 04:37 Go to next message
sunanda
Messages: 6
Registered: January 2006
Location: Bangalore
Junior Member

hi all..
Am the new member of this forum. I need help in writing perl script.
i wanna replace 9th line of a file with some other text. the file contains 15 lines. AND print the file conents.. Using linux platform
i wanna do this using perl.

Waiting for the hints n script..

Thanks in advance.

Regards
sunanda :-)
Re: file handling using perl [message #153721 is a reply to message #153423] Tue, 03 January 2006 20:52 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
Don't have perl on this computer, but give this a go.

perl -p -e '$_ = "New line 9" if $. == 9' filename.txt


_____________
Ross Leishman
Re: file handling using perl [message #154544 is a reply to message #153721] Mon, 09 January 2006 06:14 Go to previous message
sunanda
Messages: 6
Registered: January 2006
Location: Bangalore
Junior Member

hi..
Thanks a lot Ross Leishman
but that is in command line.. It works well..
but can u write perl script by opening a file..
after executing the script there should be permanent change in the file..
the command line execution changes only in the output but after opening the file there is no change.

Thanks n Regards
sunanda
Previous Topic: HP-UX 64Bit OS Block Size?
Next Topic: MP-RAS NCR command uselib AIX equivalent
Goto Forum:
  


Current Time: Thu Mar 28 10:20:23 CDT 2024