R.Singh@massey.ac.nz (R. Singh) (06/26/91)
Assume a file with 10 foxes. foxes foxes foxes foxes foxes foxes foxes foxes foxes foxes I want to change it to foxes1 foxes2 foxes3 foxes4 foxes5 foxes6 foxes7 foxes8 foxes9 foxes10 Is it possible in VI. Thanx Raminder $ingh
wyle@nessie.cs.id.ethz.ch (Mitchell Wyle) (06/26/91)
In <1991Jun26.031232.29957@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) asks: >Assume a file with 10 foxes. > >I want to change it to > >foxes1 >foxes2 >[...] >foxes10 > >Is it possible in VI. [?] No. Use awk. awk '{print $0 ++i}' < infile > outfile From inside vi: :%!awk '{print $0 ++i}' If you do it often, in ~/.exrc, map ;nu :%!awk '{print $0 ++i}'^V^M If you want to do it only on the current paragraph: }!awk '{print $0 ++i}' etc.
tchrist@convex.COM (Tom Christiansen) (06/26/91)
From the keyboard of R.Singh@massey.ac.nz (R. Singh): |Assume a file with 10 foxes. | |foxes |foxes |foxes |foxes |foxes |foxes |foxes |foxes |foxes |foxes | |I want to change it to | |foxes1 |foxes2 |foxes3 |foxes4 |foxes5 |foxes6 |foxes7 |foxes8 |foxes9 |foxes10 | |Is it possible in VI. All things are possible; not all are expedient. For both, try this: :%!perl -pe 's/$/$./' or this. :%!awk '{print $0 NR}' or whatever. I dare say even nroff filters are possible, but then we're probably straying a bit from expediency. :-) --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."
hansm@cs.kun.nl (Hans Mulder) (06/26/91)
In <1991Jun26.031232.29957@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) writes:
)Assume a file with 10 foxes.
)foxes
)foxes
)foxes
)foxes
)foxes
)foxes
)foxes
)foxes
)foxes
)foxes
)I want to change it to
)foxes1
)foxes2
)foxes3
)foxes4
)foxes5
)foxes6
)foxes7
)foxes8
)foxes9
)foxes10
)Is it possible in VI.
No. You'll have to use an external filter, e.g.
1G!G awk '{print $0 NR}'
Change the 1G!G bit to taste (and the awk program for that matter).
--
Have a nice day,
Hans Mulder hansm@cs.kun.nl