1

I have a text like this:

    LDX LEVEL
    LDA INITD015,X       ; INITIAL ACTIVE SPRITES
    STA $D015
    STA SAVED015
    LDA INITXPOS,X      ; INITIAL HERO X COORDINATE
    STA XPOS
    LDA INITYPOS,X               ; INITIAL HERO Y COORDINATE
    STA YPOS
    LDA INITXPOSMUM,X            ; INITIAL MUMMY X COORDINATE
    STA XPOSMUM
    LDA LEVEL
    BNE NOTLOADENDELEMENTS
    LDA FLAGLOSELIFE
    BNE NOTLOADENDELEMENTS
;    LDX #<BIGELEMENTSFILE  ; LOW BYTE
;    LDY #>BIGELEMENTSFILE ; HI BYTE
;    JSR LOADFILE_EXOMIZER

where i need to align text starting at ";" that IS NOT first char of a line, to end of line, at char number 41 of the line. Lines starting with ";" must be untouched until (and if) the second ";" is ecountred, then staring from second ";" to end of line should be aligned at char 41. Maybe the second ";" is before or after char 41.

Can be this achieved using SED or AWK?

1 Answer 1

3

How about perl?

perl -pe 's/^(.+?)(?=;)/$1 . " "x(41-length($1))/e' file
    LDX LEVEL
    LDA INITD015,X                       ; INITIAL ACTIVE SPRITES
    STA $D015
    STA SAVED015
    LDA INITXPOS,X                       ; INITIAL HERO X COORDINATE
    STA XPOS
    LDA INITYPOS,X                       ; INITIAL HERO Y COORDINATE
    STA YPOS
    LDA INITXPOSMUM,X                    ; INITIAL MUMMY X COORDINATE
    STA XPOSMUM
    LDA LEVEL
    BNE NOTLOADENDELEMENTS
    LDA FLAGLOSELIFE
    BNE NOTLOADENDELEMENTS
;    LDX #<BIGELEMENTSFILE               ; LOW BYTE
;    LDY #>BIGELEMENTSFILE               ; HI BYTE
;    JSR LOADFILE_EXOMIZER

awk

awk '
    (p=index(substr($0,2), ";")) > 0 {
        printf "%-40s%s\n", substr($0,1,p), substr($0,p)
        next
    }
    {print}
' file
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .