 | | From: | Jeff | | Subject: | vi editor replacing lines... | | Date: | 20 Jan 2005 10:25:56 -0800 |
|
|
 | My question is I have alot of multiple changes to make to a program that have the same variables in different names The extract below is a part of about 300 lines MOVE 0 TO ENERGY OF BILLHIST OF GRAND-TOTALS 05020177 fUEL OF BILLHIST OF GRAND-TOTALS 05020177 DEMANDAMT OF BILLHIST OF GRAND-TOTALS 05020177 etc.
My question is I wanna change like 300 lines of code using the vi editor. Starting from line 2300 to 2600. I know how to do some replacing in vi: prompt>:%s/type/types
What is the format to replace starting at line 2300 to 2600 Grand totals with dist-totals, keep in mind this is cobol and I need to keep 05020177 in colums 73-80.
|
|
 | | From: | Martin Kissner | | Subject: | Re: vi editor replacing lines... | | Date: | 21 Jan 2005 10:39:49 GMT |
|
|
 | Jeff wrote : > My question is I have alot of multiple changes to make to a program > that have the same variables in different names The extract below is a > part of about 300 lines > MOVE 0 TO > ENERGY OF BILLHIST OF GRAND-TOTALS 05020177 > fUEL OF BILLHIST OF GRAND-TOTALS 05020177 > DEMANDAMT OF BILLHIST OF GRAND-TOTALS 05020177 > etc. > > My question is I wanna change like 300 lines of code using the vi > editor. Starting from line 2300 to 2600. I know how to do some > replacing in vi: > prompt>:%s/type/types > > What is the format to replace starting at line 2300 to 2600 > Grand totals with dist-totals, keep in mind this is cobol and I need to > keep 05020177 in colums 73-80. >
prompt>:2300,2600s/Grand totals/dist-totals/g
the g at the end is needed if there are more than one occurences of "Grand totals" in on line which should all be changed.
HTH Martin
-- Epur Si Muove (Gallileo Gallilei)
|
|
 | | From: | jxh | | Subject: | Re: vi editor replacing lines... | | Date: | 21 Jan 2005 13:19:35 -0800 |
|
|
 | Ian Wilson wrote: > Jeff wrote: > > My question is I have alot of multiple changes to make to a program > > that have the same variables in different names The extract below is a > > part of about 300 lines > > MOVE 0 TO > > ENERGY OF BILLHIST OF GRAND-TOTALS 05020177 > > fUEL OF BILLHIST OF GRAND-TOTALS 05020177 > > DEMANDAMT OF BILLHIST OF GRAND-TOTALS 05020177 > > etc. > > > > My question is I wanna change like 300 lines of code using the vi > > editor. Starting from line 2300 to 2600. I know how to do some > > replacing in vi: > > prompt>:%s/type/types > > > > What is the format to replace starting at line 2300 to 2600 > > Grand totals with dist-totals, keep in mind this is cobol and I need to > > keep 05020177 in colums 73-80. > > > > :2300,2600s/GRAND-TOTALS/DIST-TOTALS / > > Note the extra space to keep your columns 73-80 aligned.
And although somewhat obvious, if you are substituting to something longer, put spaces in your target.
SNIP :2300;+300s/DIST-TOTALS /GRAND-TOTALS/g SNIP
Suppose you forgot to properly pad your substitutions, and your punch card tags are now misaligned. You can do something like this:
SNIP :%s/05020177$/ &/ :g/05020177$/s/^\(.\{72\}\) */\1/ SNIP
-- James -- http://www.ungerhu.com/jxh/vi.html
|
|
 | | From: | Ian Wilson | | Subject: | Re: vi editor replacing lines... | | Date: | Fri, 21 Jan 2005 19:22:46 +0000 (UTC) |
|
|
 | Jeff wrote: > My question is I have alot of multiple changes to make to a program > that have the same variables in different names The extract below is a > part of about 300 lines > MOVE 0 TO > ENERGY OF BILLHIST OF GRAND-TOTALS 05020177 > fUEL OF BILLHIST OF GRAND-TOTALS 05020177 > DEMANDAMT OF BILLHIST OF GRAND-TOTALS 05020177 > etc. > > My question is I wanna change like 300 lines of code using the vi > editor. Starting from line 2300 to 2600. I know how to do some > replacing in vi: > prompt>:%s/type/types > > What is the format to replace starting at line 2300 to 2600 > Grand totals with dist-totals, keep in mind this is cobol and I need to > keep 05020177 in colums 73-80. >
:2300,2600s/GRAND-TOTALS/DIST-TOTALS /
Note the extra space to keep your columns 73-80 aligned.
|
|
 | | From: | David de Kloet | | Subject: | Re: vi editor replacing lines... | | Date: | Thu, 20 Jan 2005 20:49:29 +0100 |
|
|
 | On Thu, 20 Jan 2005, Jeff wrote:
> My question is I have alot of multiple changes to make to a program > that have the same variables in different names The extract below is a > part of about 300 lines > MOVE 0 TO > ENERGY OF BILLHIST OF GRAND-TOTALS 05020177 > fUEL OF BILLHIST OF GRAND-TOTALS 05020177 > DEMANDAMT OF BILLHIST OF GRAND-TOTALS 05020177 > etc. > > My question is I wanna change like 300 lines of code using the vi > editor. Starting from line 2300 to 2600. I know how to do some > replacing in vi: > prompt>:%s/type/types > > What is the format to replace starting at line 2300 to 2600 > Grand totals with dist-totals, keep in mind this is cobol and I need to > keep 05020177 in colums 73-80.
I don't know cobol but if :%s/type/types works correctly for the whole file, :2300,2600s/type/types should work for lines 2300 to 2600.
-- David
|
|
 | | From: | Bob Harris | | Subject: | Re: vi editor replacing lines... | | Date: | Fri, 21 Jan 2005 02:44:31 GMT |
|
|
 | In article , David de Kloet wrote:
> On Thu, 20 Jan 2005, Jeff wrote: > > > My question is I have alot of multiple changes to make to a program > > that have the same variables in different names The extract below is a > > part of about 300 lines > > MOVE 0 TO > > ENERGY OF BILLHIST OF GRAND-TOTALS 05020177 > > fUEL OF BILLHIST OF GRAND-TOTALS 05020177 > > DEMANDAMT OF BILLHIST OF GRAND-TOTALS 05020177 > > etc. > > > > My question is I wanna change like 300 lines of code using the vi > > editor. Starting from line 2300 to 2600. I know how to do some > > replacing in vi: > > prompt>:%s/type/types > > > > What is the format to replace starting at line 2300 to 2600 > > Grand totals with dist-totals, keep in mind this is cobol and I need to > > keep 05020177 in colums 73-80. > > I don't know cobol but if :%s/type/types works correctly for the whole > file, :2300,2600s/type/types should work for lines 2300 to 2600.
And keeping 0502177 in columns 73-80 is just a matter of making sure that is you substitute a shorter name that you pad out the new name with spaces. If you are replacing a shorter name with a longer one, then if possible include spaces in match such that you are finding and replacing the same number of spaces.
Bob Harris
|
|