Help with AWK

Ian Ornstein x2754 DEC Software Services @ Dupont ORNSTEIK%MYIPA at dupont.com
Tue May 7 05:45:06 AEST 1991


Mario at wjvax.uucp asked for help with AWK to reformat a mailing list.
He is a solution using MicroEMACS macros:

select-buffer   "Data"
    beginning-of-file
    set-mark
    end-of-file
    kill-region
select-buffer   "Result"
    beginning-of-file
    set-mark
    end-of-file
    kill-region
;
store-procedure Do-one-line
    set-mark
    set $curcol 10
    copy-region
    select-buffer "Result"
    yank
    newline
    select-buffer "Data"
    set-mark
    set $curcol 29
    copy-region
    select-buffer "Result"
    yank
    newline
    select-buffer "Data"
    set-mark
    set $curcol 46
    copy-region
    !if &sequel $kill "                 "
;                      1234567890123456789012345678901234567890
        set %talley 0
    !else
        select-buffer "Result"
        yank
        newline
        select-buffer "Data"
    !endif
    set-mark
    set $curcol 70
    copy-region
    select-buffer "Result"
    yank
;    newline
    select-buffer "Data"
    set-mark
    end-of-line
;   backward-character
    copy-region
    select-buffer "Result"
    previous-word
    search-forward " "
    yank
    2 newline
!endm
;
;
select-buffer   "Data"
insert-file     "puzzle.dat"
set %talley 0
beginning-of-file
end-of-file
set %maxlines   &sub $curline 1
beginning-of-file
!while &less $curline    %maxlines
    run Do-one-line
    select-buffer "Data"
    next-line
    beginning-of-line
!endwhile
unmark-buffer
select-buffer   "Result"
    delete-previous-character
    beginning-of-file
    set-mark
    end-of-file
    trim-line
    write-file      "file.out"
set $discmd TRUE
;exit-emacs

                                        Enjoy!



More information about the Comp.unix.questions mailing list