Opening file...replace text...close file

HI,

I'm new to this list. I would like to know how I can open an existing file on the server (windows). Search for some text and once found replace it with 
something else and then save/close the file.

Thanks


---------------------------------------------------
Colonel Nathan R. Jessop
Commanding Officer
Marine Ground Forces
Guatanamo Bay, Cuba
---------------------------------------------------




0
flashmx
4/7/2003 11:19:24 PM
perl.beginners 29381 articles. 4 followers. Follow

2 Replies
794 Views

Similar Articles

[PageSpeed] 15


FlashGuy wrote:

>HI,
>
>I'm new to this list. I would like to know how I can open an existing file on the server (windows). Search for some text and once found replace it with 
>something else and then save/close the file.
>  
>

For opening and closing a file
perldoc -f open
perldoc perlopentut
perldoc -f close

For search and replace
perldoc perlre

A FAQ pointer that also has a code example
perldoc -q 'How do I change one line in a file/delete a line in a 
file/insert a line in the middle of a file/append to the beginning of a 
file?'

>Thanks
>
>
>---------------------------------------------------
>Colonel Nathan R. Jessop
>Commanding Officer
>Marine Ground Forces
>Guatanamo Bay, Cuba
>---------------------------------------------------
>
>
>
>
>
>  
>


0
sraghav
4/8/2003 6:06:20 AM
FlashGuy wrote:

> HI,
>
> I'm new to this list. I would like to know how I can open an existing file on the server (windows). Search for some text and once found replace it with
> something else and then save/close the file.
>
> Thanks

Only if the replacement text is of exactly the same length as that being replaced.  There is an "in-place" editing function that provides an illsusion of
editinga file on a single open.  Nevertheless, this function only abstracts the process of transcription and renaming.  This is why one of the parameters
requires an extension for a backup file.

I see the read-write open mode as a relic of a time when operating systems were routinely used to do application-level work.  This mode was used for data
access in files with fixed widthrecords and fields.  It could be very fast because if the index of the needed record was known, it was simple arithmetic to
go to an offset of record_length * index to access the record in question.  Since such records were always of fixed length, in-plce editing on a given
record would be a fairly straightforward process.

There are storage schemas that can make access to and editing of "sequential" files more efficient, but these schemas are not strictly sequential.  The
first that comes to mind is padded storage on a linked or indexed list of partially-storage blocks. Some systems may implement such storage management
schemas--I don't know.  By doing this, though you could achieve some of the efficiencies of in-place editing by having to re-write only the block
containing the text being editied while surrounding blocks ere left undisurbed.

AFAIK, this sort of editing is not readily available in Perl.  I would joyously accept correction on this point, though.

Joseph



0
rjnewton
4/8/2003 7:18:59 AM
Reply:

Similar Artilces:

File open/lock Monitor on one file closes when user accesses this file
Hello, we are running a DBase 4.1.1 MS-DOS application at Netware OES 6.5 SP4 (Novell Small Business Suite Server). Sometimes we are experiencing a slow down of the application when the server CPU ha about 5% and the disks are also not running heavy. There is nothing to find in the network too. What we found today is, that when a user accesses ex. file.dbf and we open the "File open/lock activity" Monitor on this file, the monitor closes immediately. We can shortly see the users session (nolock) before it closes. Are there any hints we can follow to find the backgrou...

File Upload Problem
Hi Everyone,I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.The original code is as follows: <%@ Page Language="VB" MasterPageFile="~/MasterP...

superreview requested: [Bug 363654] .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch : [Attachment 248458] disables .url in file:open
Smokey Ardisson (unreliable; no bugmail) <alqahira@ardisson.org> has asked Stuart Morgan <stuart.morgan@alumni.case.edu> for superreview: Bug 363654: .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch https://bugzilla.mozilla.org/show_bug.cgi?id=363654 Attachment 248458: disables .url in file:open https://bugzilla.mozilla.org/attachment.cgi?id=248458&action=edit ------- Additional Comments from Smokey Ardisson (unreliable; no bugmail) <alqahira@ardisson.org> Asking for sr on this 7-char patch in case we need to take it ...

superreview granted: [Bug 363654] .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch : [Attachment 248458] disables .url in file:open
Stuart Morgan <stuart.morgan@alumni.case.edu> has granted Smokey Ardisson (unreliable; no bugmail) <alqahira@ardisson.org>'s request for superreview: Bug 363654: .url files opened via File:Open don't open/don't open properly on the 1.8.0 branch https://bugzilla.mozilla.org/show_bug.cgi?id=363654 Attachment 248458: disables .url in file:open https://bugzilla.mozilla.org/attachment.cgi?id=248458&action=edit ------- Additional Comments from Stuart Morgan <stuart.morgan@alumni.case.edu> Well, that kinda sucks. ...

superreview requested: [Bug 243324] Download manager fails to close with files that download very quickly (small files / cached files) : [Attachment 164720] check closeWhenDone pref before opening do
Son Le <lesx99@lycos.com> has asked Ben Goodger <bugs@bengoodger.com> for superreview: Bug 243324: Download manager fails to close with files that download very quickly (small files / cached files) https://bugzilla.mozilla.org/show_bug.cgi?id=243324 Attachment 164720: check closeWhenDone pref before opening download window (v2) https://bugzilla.mozilla.org/attachment.cgi?id=164720&action=edit ...

superreview cancelled: [Bug 243324] Download manager fails to close with files that download very quickly (small files / cached files) : [Attachment 164976] check closeWhenDone pref before opening do
Son Le <lesx99@lycos.com> has cancelled Son Le <lesx99@lycos.com>'s request for superreview: Bug 243324: Download manager fails to close with files that download very quickly (small files / cached files) https://bugzilla.mozilla.org/show_bug.cgi?id=243324 Attachment 164976: check closeWhenDone pref before opening download window (v3) https://bugzilla.mozilla.org/attachment.cgi?id=164976&action=edit ...

superreview requested: [Bug 243324] Download manager fails to close with files that download very quickly (small files / cached files) : [Attachment 164976] check closeWhenDone pref before opening do
Son Le <lesx99@lycos.com> has asked Ben Goodger <bugs@bengoodger.com> for superreview: Bug 243324: Download manager fails to close with files that download very quickly (small files / cached files) https://bugzilla.mozilla.org/show_bug.cgi?id=243324 Attachment 164976: check closeWhenDone pref before opening download window (v3) https://bugzilla.mozilla.org/attachment.cgi?id=164976&action=edit ...

superreview cancelled: [Bug 243324] Download manager fails to close with files that download very quickly (small files / cached files) : [Attachment 164720] check closeWhenDone pref before opening do
Son Le <lesx99@lycos.com> has cancelled Son Le <lesx99@lycos.com>'s request for superreview: Bug 243324: Download manager fails to close with files that download very quickly (small files / cached files) https://bugzilla.mozilla.org/show_bug.cgi?id=243324 Attachment 164720: check closeWhenDone pref before opening download window (v2) https://bugzilla.mozilla.org/attachment.cgi?id=164720&action=edit ...

Replacing text with images in word file and saving the file to webserver
Hello All,  How to replace text  with images in word file and saving the file to webserver at runtime? Suppose Word file is contains the word "Image" then this word can be replaced with Image.jpg As Replacement of Word by Word is possible but if I want to replace Word by Image ..how its possible? Swati Swati Jain:Hello All,  How to replace text  with images in word file and saving the file to webserver at runtime? Suppose Word file is contains the word "Image" then this word can be replaced with Image.jpg As Replacement of Word by W...

Which is better, opening and closing, or a massive file opening and a massive closing?
I'm still working on the script, though it is cleaning up even better, I even have it running cleaner by dumping anything not matching some specs=2E= =20 What I am trying to figure out though is this: I have 42 places for the output to go, 1 of those is a constant dump, the others are all based on whether or not there is data in a field=2E If the= data is in the field, the data writes to a file with the same name as the data checked=2E If not then it writes to a global catch-all=2E <!-- snip --> open OUTFILE, ">/home/multifax/everyone" or die "C...

How to append a text file to an existing text file
Hello, Is there a way to append a text file to an existing text file. For example, File A: Jan Feb Mar April ... File B: 10 30 40 20 ... After appending job, the File A would be like below. Jan Feb Mar April ... 10 30 40 20 ... TIA Hi, It's a basic job in Perl, just open, read, and print. open B with read mode; read the content of B into memory (ie, save to a variable); close B; open A with append mode; write B's content to A; close A; 2008/9/19 Back9 <backgoodoo@gmail.com>: > Hello, > > Is there a way to append a text file to...

to file:// or not to file://
(Firefox 1.5.0.6) I'm having trouble with HTML Anchors (links) using the file: protocol. The URL I'm trying to get at looks something like this file://///Host.Domain/Share/Dir1/Dir2/File.Ext If I click on the link, /nothing/ happens but, if I "Copy Link Location" and paste exactly the same thing into the "address bar" in FireFox, FireFox is perfectly happy to show me the file. Why the difference? Am I tripping over some security restriction here? Any suggestions? TIA, Phill W. Phill W. wrote: > (Firefox 1.5.0.6) > I'm ...

Append a text file to an existing text file
Hello, Is there a way to append a text file to an existing text file. For example, File A: Jan Feb Mar April ... File B: 10 30 40 20 ... After appending job, the File A would be like below. Jan Feb Mar April ... 10 30 40 20 ... TIA On Sep 18, 11:49=A0am, backgoo...@gmail.com (Back9) wrote: > Hello, > > Is there a way to append a text file to an existing text file. > For example, > File A: > Jan Feb Mar April ... > > File B: > 10 30 40 20 ... > > After appending job, the File A would be like below. > Jan Feb Mar April ... &g...

Load a Text File, Search a Text File
I'd like to load a text file that has a list of target words and replacement words. After loading the list, I'll replace all words with the target word. I've got the code worked out to do the replacing, now I just need some help with how to actually load and search the text file (xml). Here what it looks like: <dictionary> <entry> <word>Word1</word> <equivalent>Word1R1</equivalent> <equivalent>Word1R2</equivalent> <equivalent>Word1R3</equivalent> </entry> </dictionary> Th...

Web resources about - Opening file...replace text...close file - perl.beginners

2010 Winter Olympics opening ceremony - Wikipedia, the free encyclopedia
Canadian fiddlers perform during the Opening Ceremony of the XXI Olympic Winter Games, Feb. 12, 2010, at BC Place stadium in Vancouver. The Opening ...

Facebook Testing Opening Of Facebook.com Links By Android App?
Facebook appears to be using the latest beta version of its Android application to quietly test allowing the app to open facebook.com links, ...

Into Film Festival opening Q&A
Today I met Malala. She was giving, utterly graceful, compelling and intelligent. That might sound obvious but I was struck by this even more ...

Perth pub, nightclub opening hours to extend - Sunday Sessions, WA
AS THE east coast of Australia cracks down on late-night drinking, Western Australia is heading in the opposite direction.

Liveblogging World War II: Robert H. Jackson: Opening Statement before the International Military Tribunal ...
**Robert H. Jackson**: [Opening Statement before the International Military Tribunal](https://www.roberthjackson.org/speech-and-writing/open ...

Asbury Park venue House of Independents opening this week with Murphy's Law and Fishbone
Asbury Park is getting a new venue this week called House of Independents, located at 732 Cookman Ave. Opening night is Tuesday (11/24) with ...

The latest 'Hunger Games' movie has 5th largest opening of 2015, but lowest in the franchise
... by author Suzanne Collins hit the big screen this weekend. Like its predecessors, "The Hunger Games: Mockingjay - Part 2" had a monster opening ...

Square spikes 50% after opening at $11.20 a share
The mobile payments company began its trading debut at $11.20 a share on Thursday, after pricing at $9 a day earlier.

Wordless ‘Carol’ Trailer Arrives After Strong Art House Opening
Right after Carol posted the third-highest per-theater average of 2015 in its opening weekend, the Weinstein Company has issued a new dialogue-free ...

'Project X Zone 2' Has A Truly Awesome Opening Animation
While a few sites already tried to rip the opening animation from the recently released 3DS games Project X Zone 2, Bandai Namco has finally ...

Resources last updated: 11/27/2015 2:55:13 PM