Operating System - HP-UX
1832791 Members
2770 Online
110045 Solutions
New Discussion

Re: Changing many words into a file using vi

 
SOLVED
Go to solution
Manuales
Super Advisor

Changing many words into a file using vi

how can i change many files into a file using vi editor?

THANKS.
12 REPLIES 12
Marvin Strong
Honored Contributor
Solution

Re: Changing many words into a file using vi

you want to add many files to 1 file? with vi

in command mode :r filename will read in the new file and you then you can save.

it would be easier to use the commandline with >> imo
James R. Ferguson
Acclaimed Contributor

Re: Changing many words into a file using vi

Hi Manuales:

I believe you want:

1. Position your cursor where ever it is that you want to add the contents of another file;

2. Type a colon character (":") followed by an "r" (for "read"); a space, and the name of the file that you want inserted.

Regards!

...JRF...
OldSchool
Honored Contributor

Re: Changing many words into a file using vi

or "cat"
Jaime Bolanos Rojas.
Honored Contributor

Re: Changing many words into a file using vi

Manuales,

This are the options in vi to replace text:

Replacing Text: This amounts to combining two steps; deleting, then inserting text.

r replace 1 character (under the cursor) with another character
8r replace each of the next 8 characters with a given character
R overwrite; replace text with typed input, ended with Esc
C replace from cursor to end of line, with typed input (ended with Esc)
S replace entire line with typed input (ended with Esc)
4S replace 4 lines with typed input (ended with Esc)
cw replace (remainder of) word with typed input (ended with Esc)


And this is the link to the source of information, you may want to add it your favorites:

http://amath.colorado.edu/computing/unix/vi/

Regards,

Jaime.
Work hard when the need comes out.
spex
Honored Contributor

Re: Changing many words into a file using vi

Hi Manuales,

'cat' may be a better choice:

# cat f1 f2 f3 f4 > f5

PCS
Sp4admin
Trusted Contributor

Re: Changing many words into a file using vi

Hi,

How about...

:nr file **read file and insert after line number.

or

:r file ** Read file and insert after the current line.

sp,
KapilRaj
Honored Contributor

Re: Changing many words into a file using vi

The subject and content shows diffrences. So give us detailed information for the best results.
Nothing is impossible
Manuales
Super Advisor

Re: Changing many words into a file using vi

Hi ...
i want to know something about the following commando:

:%s/Joe/Bob/g

do i have to use it how above is shown?

Thanks, Manuales.
spex
Honored Contributor

Re: Changing many words into a file using vi

Manuales,

From the "Vi Quick Reference":
http://www.yingjenie.com/ying/linux/vi/

Replace next occurrence of old with new
:s/old/new

Replace all occurrences on the line
:s/old/new/g

Replace all occurrences from line x to y
:x,ys/old/new/g

Replace all occurrences in file
:%s/old/new/g

Replace all occurrences in file w/confirmation
:%s/old/new/gc

PCS

KapilRaj
Honored Contributor

Re: Changing many words into a file using vi

I don't know if ";" works a s field seperator in HPUX's vi. But it works in linux and aix.

So I use ,

:%s;;;g

This way I can replace /dev/vg00 with /dev/vg01. If I go with "/" as delimiter I would have to type

:%s/\/dev\/vg00/\/dev\/vg01/g

Regds,

Kaps
Nothing is impossible
IT_2007
Honored Contributor

Re: Changing many words into a file using vi

Hi ...
i want to know something about the following commando:

:%s/Joe/Bob/g

do i have to use it how above is shown?

Thanks, Manuales.
========================

If you use above syntax in vi then it will replace "Joe" to "Bob" in the whole file.
Arturo Galbiati
Esteemed Contributor

Re: Changing many words into a file using vi

Hi,
to chnage all 'A' to 'B':
:%s/A/B/G

HTH,
Art