sort, cut and paste

  • I need to perform some sorting, cutting and pasting in my Cocoa app on ASCII
    files. No - not the cutting and pasting found under the edit menu, but like
    the commands used at the command line. In "Building Cocoa Applications" from
    O'Reilly, I noticed they created a small app with lex and yacc and then linked it
    with the Cocoa application with a pipe from within Project Builder/Xcode.

    Is it possible to do this as well with the cut, sort, paste and join commands
    used in bash? Or am I going about this the wrong way? Are there similar Cocoa
    API's that do this?

    The text files are all fixed width and are comma delimited.
  • On Thu, 26 Oct 2006 14:49:00 EDT, <PRzeznik...> said:
    > I need to perform some sorting, cutting and pasting in my Cocoa app on ASCII
    > files. No - not the cutting and pasting found under the edit menu, but like
    > the commands used at the command line. In "Building Cocoa Applications" from
    > O'Reilly, I noticed they created a small app with lex and yacc and then linked
    it
    > with the Cocoa application with a pipe from within Project Builder/Xcode.
    >
    > Is it possible to do this as well with the cut, sort, paste and join commands
    > used in bash? Or am I going about this the wrong way? Are there similar Cocoa
    > API's that do this?
    >
    > The text files are all fixed width and are comma delimited.

    You probably want to use NSTask. It is your gateway to the command line. You
    can include a script in Perl or Ruby or whatever you like, in your bundle,
    and run it. m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • In a message dated 10/26/06 3:36:25 PM, <matt...> writes:
    > You probably want to use NSTask. It is your gateway to the command line.
    > You
    > can include a script in Perl or Ruby or whatever you like, in your bundle,
    > and run it. m.
    >
    K.. I'll start reading the documentation for NSTask. Thanks
  • On 26 Oct 06, at 11:49, <PRzeznik...> wrote:
    > I need to perform some sorting, cutting and pasting in my Cocoa app
    > on ASCII
    > files. No - not the cutting and pasting found under the edit menu,
    > but like
    > the commands used at the command line. In "Building Cocoa
    > Applications" from
    > O'Reilly, I noticed they created a small app with lex and yacc and
    > then linked it
    > with the Cocoa application with a pipe from within Project Builder/
    > Xcode.
    >
    > Is it possible to do this as well with the cut, sort, paste and
    > join commands
    > used in bash? Or am I going about this the wrong way? Are there
    > similar Cocoa
    > API's that do this?

    You _can_ call out to cut/sort/paste/join, but it's probably going to
    be much easier (and faster!) to do the tasks yourself. Most of those
    tasks are pretty to implement using NSString and NSArray.
  • Am 26.10.2006 um 20:49 schrieb <PRzeznik...>:
    > I need to perform some sorting, cutting and pasting in my Cocoa app
    > on ASCII
    > files. No - not the cutting and pasting found under the edit menu,
    > but like
    > the commands used at the command line. In "Building Cocoa
    > Applications" from
    > O'Reilly, I noticed they created a small app with lex and yacc and
    > then linked it
    > with the Cocoa application with a pipe from within Project Builder/
    > Xcode.

      I don't remember offhand what the cut/paste command-line tools do
    exactly, but if you want to split strings at fixed offsets or on a
    certain delimiter, you can use NSString's -substringWithRange: resp. -
    componentsSeparatedByString:, and there's a similar method in
    NSString or NSArray to paste strings together again.

      Once you have an array of the strings you need (though you'll
    probably get rows, not columns, so depending on what you're doing you
    may have to do some swapping, but that's easy), you can sort them
    just fine.

      Don't use NSTask if that works for you. Apart from the overhead
    launching of processes and passing around the text cause, there's
    other considerations, like escaping special characters, about which I
    blogged a while ago: http://zathras.de/angelweb/x2005-03-10b.htm

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • So I guess what you're saying I should do is...

    1: Cut the substrings from the main NSString at the calculated offsets
    2: Stick the sub strings into an NSArray
    3: Sort the Array
    Correct?

    That should do it. One last thing I need to so is convert the string values
    into Numerical values. What is the Cocoa equivilant to the older toolbox call
    StringToNum()?

    In a message dated 10/28/06 4:37:03 AM, <witness.of.teachtext...> writes
    > I don't remember offhand what the cut/paste command-line tools do 
    > exactly, but if you want to split strings at fixed offsets or on a 
    > certain delimiter, you can use NSString's -substringWithRange: resp. -
    > componentsSeparatedByString:, and there's a similar method in 
    > NSString or NSArray to paste strings together again.
    >
    >   Once you have an array of the strings you need (though you'll 
    > probably get rows, not columns, so depending on what you're doing you 
    > may have to do some swapping, but that's easy), you can sort them 
    > just fine.
    >
    >   Don't use NSTask if that works for you. Apart from the overhead 
    > launching of processes and passing around the text cause, there's 
    > other considerations, like escaping special characters, about which I 
    > blogged a while ago: http://zathras.de/angelweb/x2005-03-10b.htm
    >
    > Cheers,
    > -- M. Uli Kusterer
    > http://www.zathras.de
    >
    >
    >
  • Am 31.10.2006 um 18:49 schrieb <PRzeznik...>:
    > That should do it. One last thing I need to so is convert the
    > string values into Numerical values. What is the Cocoa equivilant
    > to the older toolbox call StringToNum()?

      That answer can quickly be found by looking into NSString.h. It is:

    [myString intValue]

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today