Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace line

Status
Not open for further replies.

BryanY

MIS
Aug 18, 2001
54
US
I need to be able access a text file (about 20 lines) and basically just replace the first line with custom text without changing anything else. What is the best way to do this?

(I understand that this would be much easier to do in Perl, but I don't have that option)
 
sed -e '1s/.*/foo/'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
NewHeader="My new first line"
sed "1s!.*!${NewHeader}!" /path/to/input > output

If the change must be done on the same file: man ex

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
To do the change "in place" and create backup file:
Code:
ruby -pi.bak -e 'sub(/.*/,"New") if 1==$.' myfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top