LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-05-2008, 02:21 PM   #1
cleopard
Member
 
Registered: May 2006
Posts: 39

Rep: Reputation: 15
string substitutions within a file


In a Linux C program I'm working on, there's a part where I need to substitute a string within a file with another string; the data in the file after the new string should either be moved back or moved forward, depending on whether the new string is longer or shorter than the previous one.

An example of what I'm referring to is if you have a particular web page pulled up and you save that page to disk; each of the files within that page are saved in a subdirectory, and inside the HTML file, the new pathname for each of those files replaces the original pathname, i.e., "http://www.aol.com/script.com" becomes "aol_files/script.com".

There doesn't seem to be a real efficient way to do something like this. I was thinking that since these substitutions are within a file, I could use 'mmap' and bring the file contents into memory, make the desired changes and 'munmap' it. But that wouldn't make the string modifications any more straight-forward. I thought I'd ask to see if anyone had any suggestions of ways to go about this that I hadn't thought of (other than the cumbersome method of moving the data, char-by-char, to where it's supposed to be. Thank you in advance.
 
Old 09-05-2008, 03:52 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
It is not possible to gain an understanding of your entire pattern space with just one example. If you are asking for algorithms or help designing such, we need to better clarify your pattern -> replacement transitions. Please show several example transitions.

You are correct that the input method of the file contents into your program is a different matter.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed: print section of file from string to end of file samyboy Linux - Newbie 4 02-26-2008 07:23 AM
perl- multiple substitutions on same line gnashley Programming 2 11-12-2007 08:29 AM
variables within sed substitutions? ocicat Programming 3 07-29-2007 12:17 PM
Perl: Using Vars in Substitutions cramer Programming 6 08-26-2006 12:52 PM
sed? -- making substitutions scabies Linux - Software 1 12-21-2003 11:39 PM


All times are GMT -5. The time now is 01:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration