How to do this?

0 views
Skip to first unread message

Jerrygreat

unread,
Nov 21, 2008, 1:40:01 PM11/21/08
to vim...@googlegroups.com

Hello, friends,
I have a huge file like:

dbv file=/sja7/appl/oracle/ship/system01.dbf feedback=100 logfile=./.log
blocksize=8192
dbv file=/sja8/appl/oracle/ship/undotbs.dbf feedback=100 logfile=./.log
blocksize=8192
dbv file=/sja7/appl/oracle/ship/tools.dbf feedback=100 logfile=./.log
blocksize=8192
dbv file=/sja7/appl/oracle/ship/dtuser_01.dbf feedback=100 logfile=./.log
blocksize=8192
......

how can I change it to like bleow by using one command line

dbv file=/sja7/appl/oracle/ship/system01.dbf feedback=100
logfile=./system01.log blocksize=8192
dbv file=/sja8/appl/oracle/ship/undotbs.dbf feedback=100
logfile=./undotbs.log blocksize=8192
dbv file=/sja7/appl/oracle/ship/tools.dbf feedback=100 logfile=./tools.log
blocksize=8192
dbv file=/sja7/appl/oracle/ship/dtuser_01.dbf feedback=100
logfile=./dtuser_01.log blocksize=8192
.............


Thank you very much

Jerry
--
View this message in context: http://www.nabble.com/How-to-do-this--tp20627275p20627275.html
Sent from the Vim - General mailing list archive at Nabble.com.

xulxer

unread,
Nov 21, 2008, 5:05:08 PM11/21/08
to vim...@googlegroups.com
Hi,

if you want to split the line in front of all logfile netries and join
this bit with all blocksize entries on a new line on a unix box, you can do:

%s~\(logfile.*\)\n\(.*\)~\r\1 \2~g

I don't know if you have to use \n instead \r on windows.

Kind regards

Chris
--
Bitte beachten Sie auch die Rückseite dieses Schreibens.

William Anderson

unread,
Nov 21, 2008, 5:09:45 PM11/21/08
to vim...@googlegroups.com
Jerry,

This should be pretty easy to accomplish with a simple regex. Something
like

%s#^\(dbv file=/sja./appl/oracle/ship/\)\(.\+\)\(.dbf .*logfile=\)[^
]*#\1\2\3./\2.log#

Bill

StarWing

unread,
Nov 21, 2008, 5:45:00 PM11/21/08
to vim_use
my idea, combine xulxer and william's

:%s#\(/oracle/ship/\)\(.*\)\(.dbf .*\)\(logfile=\).\{-}\n\(.*\)#
\1\2\3\r\4./\2.log \5#g

On 11月22日, 上午6时09分, William Anderson <whand...@lasthonorableman.net>
wrote:

Cesar Romani

unread,
Nov 21, 2008, 7:03:52 PM11/21/08
to vim...@googlegroups.com
:g/logfile/s//\r&/ | normal J

Regards,
Cesar

Tony Mechelynck

unread,
Nov 21, 2008, 10:22:10 PM11/21/08
to vim...@googlegroups.com
On 21/11/08 23:05, xulxer wrote:
> Hi,
>
> if you want to split the line in front of all logfile netries and join
> this bit with all blocksize entries on a new line on a unix box, you can do:
>
> %s~\(logfile.*\)\n\(.*\)~\r\1 \2~g
>
> I don't know if you have to use \n instead \r on windows.
>
> Kind regards
>
> Chris

In all versions of Vim, you _match_ a line break with \n in the first
half of a :subst command, you _insert_ one with \r in the second half.

This means that one silly way to count lines (by replacing line breaks
with themselves) is

:%s/\n/\r/


Best regards,
--
The Heineken Uncertainty Principle:
You can never be sure how many beers you had last night.

Agathoklis D. Hatzimanikas

unread,
Nov 23, 2008, 4:33:16 AM11/23/08
to vim...@googlegroups.com
On Fri, Nov 21, at 02:45 StarWing wrote:
>
> my idea, combine xulxer and william's
>
> :%s#\(/oracle/ship/\)\(.*\)\(.dbf .*\)\(logfile=\).\{-}\n\(.*\)#
> \1\2\3\r\4./\2.log \5#g


While regular expressions can do wonders, here is yet
another way to solve your problem using VimL:


let line = 1
while line < line('$')
let fline = split(getline(line))[:2]
let logfile = fnamemodify(fline[1], ":t:r")
call setline(line, join(fline))
call setline((line + 1), 'logfile=./'.logfile.'.log '.getline((line + 1)))
let line += 2
endwhile

Regards,
Ag.

Reply all
Reply to author
Forward
0 new messages