coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enhancement suggestions for "sort" and text editor


From: Assaf Gordon
Subject: Re: enhancement suggestions for "sort" and text editor
Date: Fri, 14 Dec 2012 16:27:49 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Hello John,

Eric Blake wrote, On 12/14/2012 04:19 PM:
> On 12/14/2012 02:02 PM, john wrote:
>>
>> In particular I wish to enter text into predefined (fixed location)
>> fields in a record as opposed to variably delimited fields.  In other
>> words emulate the punched card record where card columns are assigned to
>> particular data character columns.  Those card columns then just become
>> a text column range of a single record.  If I could just set perhaps 10
>> arbitrary tab stops (in any simple editor), it would be sufficient for
>> this purpose.  The tab key would just advance to the next stop in
>> succession, tho not necessarily regularly spaced.
> 
> Sounds like you are talking in part about 'expand -t', which lets you
> re-expand tabs according to your choice of pre-defined stops.  Beyond
> that, your question is out of scope for coreutils, and better directed
> to the editor of your choice (I'm quite sure that emacs is probably
> going to have something that does what you want, although I don't use
> arbitrary tab stops enough to be able to tell you off-hand how to get at
> that feature)
> 

(Slightly off-topic for coreutils, but for completeness:)

Recent versions of GNU awk (gawk) support exactly this kind of processing:

    $ printf "0000AAAAxx33333\n1234BBBByy98765\n" | gawk -v FIELDWIDTHS="4 4 2 
5" '{print $1,$2,$3,$4}'
    0000 AAAA xx 33333
    1234 BBBB yy 98765

Or with Tab-separated output:

    $ printf "0000AAAAxx33333\n1234BBBByy98765\n" | gawk -v FIELDWIDTHS="4 4 2 
5" -v OFS="\t" '{print $1,$2,$3,$4}'
    0000        AAAA    xx      33333
    1234        BBBB    yy      98765

More information here:
 http://www.gnu.org/software/gawk/manual/html_node/Constant-Size.html

-gordon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]