LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-07-2004, 01:49 PM   #1
stellarmarine1
Member
 
Registered: Jul 2004
Distribution: RedHat AS 2.1
Posts: 51

Rep: Reputation: 15
replacing specific lines in a text document


Is there a way to write a script that would overwrite specific lines in a text file. For instance I would like to change the 1st and 4th line in a text file. How would I go about doing this while incorporating it into a script?

I hate to keep asking all these script writing questions. But it seems that there are so many tutorials out there that I don't know which one to follow.

Any suggestions?
 
Old 09-07-2004, 02:34 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
man sed

sed -e 'n c <text>' <file>


Where n is the line-number, c the sed command,
<text> the text you want to be on the n'th line.



Cheers,
Tink
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cat: output specific number of lines mikeshn Linux - Software 8 01-24-2017 11:08 AM
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM
Unique lines based on specific fields. carl.waldbieser Programming 6 08-21-2005 02:26 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Replacing text in a specific field Seventh_Warrior Programming 5 04-11-2005 12:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:42 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration