Unix Shell - how to edit only one paragraph

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > how to edit only one paragraph





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author how to edit only one paragraph
angel

2006-01-05, 6:08 pm

HI,

I want to do some global change in one paragraph of my file.

Is there any way to do that?

Thanks.

Janis Papanagnou

2006-01-05, 6:08 pm

angel wrote:
> HI,
>
> I want to do some global change in one paragraph of my file.


Define "global change".
Define "paragraph".

Provide sample data.

> Is there any way to do that?
>
> Thanks.
>

Sashi

2006-01-05, 6:08 pm

Using VI you can specify a range of lines to modify for the editing
command that you use such that your changes are only updated to the
paragraph you're interested in.
Sashi

Janis Papanagnou wrote:[vbcol=seagreen]
> angel wrote:
>
> Define "global change".
> Define "paragraph".
>
> Provide sample data.
>

angel

2006-01-05, 6:08 pm

HI, Thanks for the reply.

I have a question for Sashi, I did want to use VI to do it..

But I don't know how to use VI to specify a range..

If you could tell me the detail , I would be appreciated.

Thanks

Sashi wrote:[vbcol=seagreen]
> Using VI you can specify a range of lines to modify for the editing
> command that you use such that your changes are only updated to the
> paragraph you're interested in.
> Sashi
>
> Janis Papanagnou wrote:

angel

2006-01-05, 6:08 pm

also, I remember I used to try to highlight ( or mark) the paragraph,
then do the changes for that paragraph, I just forgot how to highlight
( or mark) the paragraph and do the change...

Thanks.

Michael Tosch

2006-01-05, 6:08 pm

angel wrote:
> HI, Thanks for the reply.
>
> I have a question for Sashi, I did want to use VI to do it..
>
> But I don't know how to use VI to specify a range..
>
> If you could tell me the detail , I would be appreciated.
>
> Thanks
>
> Sashi wrote:
>
>
>



I know the following block delimiters for the : commands

.. (dot) the current line
1 the first line
n the nth line
$ the last line
$-1 the second last line
'a the mark a
'n the mark n
'n+1 the line after mark n

Now go to the beginning of your block, do

ma

and you have set the mark a.
Then go to the end of your block, and do the substitute command
between the mark a and the current line

:'a,. s/oldstring/newstring/g

/g (global) means multiple matches within a line are all substituted.

The command
:u
undoes your change.


--
Michael Tosch @ hp : com
angel

2006-01-05, 6:08 pm

HI, Michael

Thanks.

I tried , it worked perfectly.

Janis Papanagnou

2006-01-05, 6:09 pm

angel wrote:
> also, I remember I used to try to highlight ( or mark) the paragraph,
> then do the changes for that paragraph, I just forgot how to highlight
> ( or mark) the paragraph and do the change...


[ Please always quote sufficient context. ]

Elsethread we learned that you want to use vi to edit your code.

Plain vi does not allow marking by highlighting, though vim does.
So if your vi actually is a vim or gvim then the commands...
V - start highlighting complete-line-oriented
v - start highlighting intra-line-oriented
^v - start highlighting block-oriented
then move your cursor to the end of the text to be processed and
type the command, e.g. the letter 'd' to delete. Alternatively
you may after highlighting the block of data type a colon to get
into ex-mode where you may add the command behind the preset
:'<,'> for example :'<,'>s/somepattern/newtext/g

Janis


> Thanks.
>

romy

2006-01-20, 6:03 pm

in command mode:

:line_number_1,line_number_2s/str1/str2/g

where line_number_1 is the line number of the start of paragraph
and line_number_2 is the line number of end of para.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com