Need a vim / perl guru
Author |
Message |
btiffin
|
Posted: Thu Jun 26, 2008 8:27 pm Post subject: Need a vim / perl guru |
|
|
Hello,
I'm doing some sample sources for the OpenCOBOL project. I'd like to figure out a vim trick to resequence the column 1-6 numbers.
Starting with vim: | :1,$!perl -ne'print "$. $_";' |
I'd like to get to vim: | :1,$!perl -ne'printf("\%06d\%s", $. * 10, substr($_, 7));' |
The backslashes on the format specs gets around vim substitution, not sent to perl
Attempting COBOL: |
IDENTIFICATION DIVISION.
PROGRAM-ID. SEQUENCED.
DATA DIVISION.
01 V100-ABC PIC S9(4) BINARY. |
supposed to give COBOL: |
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. SEQUENCED.
000030
000040 DATA DIVISION.
|
but I'm getting Ctrl-M's at the end of lines that have data (some runs), and no newline on source lines that are empty.
00003000040 kinda thing. The substr doesn't seem to like empty lines so much? - probably anything under 7 spaces?
COBOL: |
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. SEQUENCED.
000030000040 DATA DIVISION.
000050 01 V100-ABC PIC S9(4) BINARY.
|
So, the question is; is this the vim filter? Can I tweak perl to use different line endings? Can I chop or chomp or substr with -1 and add a \n to the formatted print or ... can I force the newline on empty $_ somehow?
Thanks in advance if you help save me digging through TFManuals.
Cheers
P.S. vim 7.1, perl 5.10.0, Debian 4 lenny
P.P.S. By the way, if it's more than a one-liner (possibly with a setting) than I'm not that interested and I'll just do it awk |
|
|
|
|
|
Sponsor Sponsor
|
|
|
btiffin
|
Posted: Thu Jun 26, 2008 9:25 pm Post subject: Re: Need a vim / perl guru |
|
|
Hi,
So far I'm using bash: |
perl -ne 'printf("%06d%s", $. * 10, substr($_, 6) ? substr($_, 6) : "\n");' < samp.txt |
for the Perl part, but that's going to be harder to type, so ... I'll still take some guru advice on this one.
Umm, and then post it to the OpenCOBOL forum to try and look smarter than I am ... you know how it goes
Cheers |
|
|
|
|
|
btiffin
|
Posted: Mon Jun 30, 2008 10:17 pm Post subject: RE:Need a vim / perl guru |
|
|
Ok, this is what I ended up with.
:%!perl -ne 'printf("\%06d\%s", $. * 10, substr($_, 6, -1) . "\n");'
Cheers |
|
|
|
|
|
|
|