Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 09-07-2004, 01:49 PM   #1
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
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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.



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

Similar Threads
Thread Thread Starter Forum Replies Last Post
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
cat: output specific number of lines mikeshn Linux - Software 3 12-31-2003 12:15 PM

All times are GMT -5. The time now is 07:40 AM.

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