Newsgroups: comp.unix.shell Date: Thu, 16 Jun 2005 23:04:04 +0200
In a file, I want to replace first line which begins with "string1" to the next line which begins with "string2" by just a line with follwing text "TEXT DELETED".
For example, test_file.c :
line 1: .......................... line 2: .......................... line 3: string0................... line 4: string1................... <---------------------- line 5: .......................... <---------------------- line 6: .......................... <---------------------- line 7: string2................... <---------------------- line 8: string3................... line 9: string4...................
After having to launch shell-script, the file becomes :
line 1: .......................... line 2: .......................... line 3: string0................... line 4: TEXT DELETED <---------------------- line 5: string3................... line 6: string4...................
Somebody would know how to make with a shell-script ?
perl -i.bak -lne' $a=/^string1/.../^string2/,$a eq 0+$a?next:s/^string2/TEXT DELETED/,print ' test_file.c
John W. Krahn
awk '/string1/{print "TEXT DELETED"}/string1/,/string2/{next}1' file
Ed Morton