ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

I am trying to write an app that will read a text file, look for specific lines and when they are found....replace that line with something else leaving the rest of the file the same. The file order must stay in tact, that is I can not just append to the end or beginning. The change needs to be made exactly where the line occurs in the text file. Can anyone help me as to how this would be done?

In a program you would have to look for the string then read the number of char in the found string rewind the file pointer back that number of charecters read the rest of the file and put that in temporary space then write the wanted charecters then write back overwriteing the remaining charecters in the file.

working with text files is a pain because when you write charecters to the file it doesent move the rest to accomidate. here is an example.

if i had a text file with the words "cat cat cat" and attempted to write cougar into the first cat then the resulting file would look like this "cougart cat"

This of course is from C programming I dunno if this is the case in others.