Click to See Complete Forum and Search --> : Patching a file without a patch file?


R-II2
09-02-2002, 01:06 AM
I have a source file, and I want to 'patch' it by inserting a line, and modifying (or replacing) a line. But I have to be able to do it via a command promt (or series of commands) with no external files involved. I know exactly what lines I want to insert or replace code, so hopefully there's some utility or even standard utility to help me do this..

Any ideas?

Rüpel
09-02-2002, 03:33 AM
so i get that right? you're searching for an editor, that is usable without X?

try pico or vim (vim is faaaaar better, but requires some learning...)

may this helps: vim is working in two different modes. command mode or edit mode. at startup you're in command mode (doing things like open, save, navigate, etc)
so type

:4711<enter> [go to line 4711]
hit 'i' [switching to edit mode]
[make your changes]
hit 'Esc' [back to command mode]
[maybe navigate to another line and edit something different things and when you're done and back in command mode type]
:wq<enter> [write changes and quit]

but be warned: editor discussion is like browser discussion is like operating system discussion is like gui-toolkit discussion is like .... everyone has it's fans and loathers ;)

TacKat
09-02-2002, 10:45 AM
Doing it in an editor (like Vim) is probably the standard way. But if you really want to do it with a series of commands, here's how that could be done. Say you want to edit the file foo.

mv foo foo.bak
sed -e '3a\
bar' -e '7a\
baz' -e '7D' foo.bak > foo

This moves foo to foo.bak so sed can work its magic (it's strange like that). The actual sed portion appends the line "bar" after line 3, appends the line "baz" after line 7, then deletes line 7. Obviously, change the line numbers and the content of the lines to whatever you want. Make sure foo has what you want, then

rm foo.bak

R-II2
09-02-2002, 12:29 PM
Thank you, that's exactly what I needed. The patching has to be done silently in an install script without any extra files (otherwise I'd have simply replaced the source page).