 | | From: | Chris Jones | | Subject: | problems actually using a macro in vi | | Date: | Fri, 14 Jan 2005 09:50:20 -0500 |
|
|
 | I've got a file of words like this:
plot_20030524.ps plot_20030525.ps plot_20030526.ps plot_20030527.ps plot_20030528.ps plot_20030529.ps
and I want to duplicate each line so it looks like this:
plot_20030524.ps plot_20030524.ps plot_20030525.ps plot_20030525.ps plot_20030526.ps plot_20030526.ps plot_20030527.ps plot_20030527.ps plot_20030528.ps plot_20030528.ps plot_20030529.ps plot_20030529.ps
Now in the actual file, there's some 500+ lines that I want to do this to. I never really messed with macros in vi, but I found that I could first add a space to the end of every line, then make a macro to do this 'yw$p' which poof duplicates the word on the same line like I want.
But what I can't figure out is to do that same command globally in the entire file. Can anybody enlighten me please? :)
Thanks in advance,
-chris
-- Chris Jones (to email me, just take out the NOSPAM)
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
|
|
 | | From: | Michael Kopp | | Subject: | Re: problems actually using a macro in vi | | Date: | Mon, 17 Jan 2005 09:40:48 +0100 |
|
|
 | In addition to the answers you already got, you could also try a copy and paste operation using visual block mode.
Michael.
|
|
 | | From: | Bob Harris | | Subject: | Re: problems actually using a macro in vi | | Date: | Fri, 14 Jan 2005 15:20:17 GMT |
|
|
 | In article , Chris Jones wrote:
> I've got a file of words like this: > > plot_20030524.ps > plot_20030525.ps > plot_20030526.ps > plot_20030527.ps > plot_20030528.ps > plot_20030529.ps > > and I want to duplicate each line so it looks like this: > > plot_20030524.ps plot_20030524.ps > plot_20030525.ps plot_20030525.ps > plot_20030526.ps plot_20030526.ps > plot_20030527.ps plot_20030527.ps > plot_20030528.ps plot_20030528.ps > plot_20030529.ps plot_20030529.ps > > Now in the actual file, there's some 500+ lines that I want to do this to. I > never really messed with macros in vi, but I found that I could first add a > space to the end of every line, then make a macro to do this 'yw$p' which > poof duplicates the word on the same line like I want. > > But what I can't figure out is to do that same command globally in the entire > file. Can anybody enlighten me please? :) > > Thanks in advance, > > -chris
Try the following:
:%s/.*/& &/
If you want to turn this into a command like a massed rename try:
:%s/.*/mv & &.old/
If you needed to change the type field from .ps to something else you could try:
:%s/\(.*\)\(\.ps\)/mv \1\2 \1.oldps/
which will change the name to *.oldps
And while I'll get yelled at for talking about non-editor stuff, when I'm doing repetitive operations on a bunch of files I do things like:
#!/usr/bin/sh while read file do cp $file /mnt/some/archive/directory/ name=`basename $file .ps` dir=`dirname $file` mv $file $dir/$name.oldps etc... done <plot_20030524.ps plot_20030525.ps plot_20030526.ps plot_20030527.ps plot_20030528.ps plot_20030529.ps EOD
Of course if I have misinterpreted what you are trying to do, please ignore me.
Have fun.
Bob Harris
|
|
 | | From: | Chris Jones | | Subject: | Re: problems actually using a macro in vi | | Date: | Fri, 14 Jan 2005 10:48:25 -0500 |
|
|
 | Bob Harris wrote: > In article , > Chris Jones wrote: > > >>I've got a file of words like this: >> >>plot_20030524.ps >>plot_20030525.ps >>plot_20030526.ps >>plot_20030527.ps >>plot_20030528.ps >>plot_20030529.ps >> >>and I want to duplicate each line so it looks like this: >> >>plot_20030524.ps plot_20030524.ps >>plot_20030525.ps plot_20030525.ps >>plot_20030526.ps plot_20030526.ps >>plot_20030527.ps plot_20030527.ps >>plot_20030528.ps plot_20030528.ps >>plot_20030529.ps plot_20030529.ps >> >>Now in the actual file, there's some 500+ lines that I want to do this to. I >>never really messed with macros in vi, but I found that I could first add a >>space to the end of every line, then make a macro to do this 'yw$p' which >>poof duplicates the word on the same line like I want. >> >>But what I can't figure out is to do that same command globally in the entire >>file. Can anybody enlighten me please? :) >> >>Thanks in advance, >> >>-chris > > > Try the following: > > :%s/.*/& &/
Bob you are the man! That command directly above was *exactly* what I was trying to do in the first place.... I just went the macro route because I couldn't figure anything out. Very sweet. I'll play around with the other stuff you said, and thanks to all the others who replied as well.
I didn't think I'd get replies that fast. Thanks to all!
-chris
> > If you want to turn this into a command like a massed rename try: > > :%s/.*/mv & &.old/ > > If you needed to change the type field from .ps to something else you > could try: > > :%s/\(.*\)\(\.ps\)/mv \1\2 \1.oldps/ > > which will change the name to *.oldps > > And while I'll get yelled at for talking about non-editor stuff, when > I'm doing repetitive operations on a bunch of files I do things like: > > #!/usr/bin/sh > while read file > do > cp $file /mnt/some/archive/directory/ > name=`basename $file .ps` > dir=`dirname $file` > mv $file $dir/$name.oldps > etc... > done <> plot_20030524.ps > plot_20030525.ps > plot_20030526.ps > plot_20030527.ps > plot_20030528.ps > plot_20030529.ps > EOD > > Of course if I have misinterpreted what you are trying to do, please > ignore me. > > Have fun. > > Bob Harris
-- Chris Jones (to email me, just take out the NOSPAM)
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
|
|
 | | From: | Julius Plenz | | Subject: | Re: problems actually using a macro in vi | | Date: | 14 Jan 2005 15:19:45 GMT |
|
|
 | * Chris Jones [2005-01-14]: > I've got a file of words like this: > > plot_20030524.ps > plot_20030525.ps > [...] > > and I want to duplicate each line so it looks like this: > > plot_20030524.ps plot_20030524.ps > plot_20030525.ps plot_20030525.ps > [...]
You can record a quick macro, type in: qq^y$A pjq Then undo the change, and enter the following: :%norm @q
Julius -- :h recording :h :normal
|
|
 | | From: | Jehannes | | Subject: | Re: problems actually using a macro in vi | | Date: | 14 Jan 2005 15:30:40 GMT |
|
|
 | Chris Jones wrote in news:cs8m7d$nni$1@news2.news.larc.nasa.gov:
> > I've got a file of words like this: > > plot_20030524.ps > plot_20030525.ps > plot_20030526.ps > plot_20030527.ps > plot_20030528.ps > plot_20030529.ps > > and I want to duplicate each line so it looks like this: > > plot_20030524.ps plot_20030524.ps > plot_20030525.ps plot_20030525.ps > plot_20030526.ps plot_20030526.ps > plot_20030527.ps plot_20030527.ps > plot_20030528.ps plot_20030528.ps > plot_20030529.ps plot_20030529.ps > > Now in the actual file, there's some 500+ lines that I want to do this > to. I never really messed with macros in vi, but I found that I could > first add a space to the end of every line, then make a macro to do > this 'yw$p' which poof duplicates the word on the same line like I > want. > > But what I can't figure out is to do that same command globally in the > entire file. Can anybody enlighten me please? :) > > Thanks in advance, > > -chris >
If you are using Vim and if your examples are complete lines you can use
%s/\(^.*$\)/\1 \1/g
Notice the space: \1\1
BTW: works in Nvi as well, so probably it'll do you some good. John -- john@beeverWITHOUTTHIS.nl
= = Sane sicut lux seipsam, & tenebras manifestat, sic veritas norma sui, & falsi est. -Spinoza- = = Posting powered by Vim 6.3 and ten fingers vim.org
|
|
 | | From: | Mikolaj Machowski | | Subject: | Re: problems actually using a macro in vi | | Date: | 14 Jan 2005 18:28:09 GMT |
|
|
 | Jehannes scripsit: > > If you are using Vim and if your examples are complete lines you can use > > %s/\(^.*$\)/\1 \1/g
For Vim you can also simplify to: %s/.*/& &/
I am also very often forgetting about \0 and & :)
m. -- LaTeX + Vim = http://vim-latex.sourceforge.net/ Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078 vim.pl - http://skawina.eu.org/mikolaj CLEWN - http://clewn.sf.net
|
|
 | | From: | Lukas Mai | | Subject: | Re: problems actually using a macro in vi | | Date: | 14 Jan 2005 16:59:31 GMT |
|
|
 | Jehannes schrob:
> If you are using Vim and if your examples are complete lines you can use
> %s/\(^.*$\)/\1 \1/g
There's no need for ^ and $ because * is greedy and .* matches anything on a line. And /g doesn't make sense here: .* can't match again after it has consumed the whole line.
> Notice the space: \1\1
> BTW: works in Nvi as well, so probably it'll do you some good. > John
HTH, Lukas -- BEGIN{$^H {q}=sub{print$_[1]};$^H |=0x28000}"Just another Perl hacker,\n"
|
|