ksh scripting problem

Discussion in 'Programmer Misc' started by Robert Peirce, Feb 8, 2008.

  1. Does anybody have any idea why this works:

    IFS=' '
    exec 0< "db/s.d"
    while read line
    do
    set $line
    if (($3>0)) && ((${15}<16))
    then

    And this doesn't?

    exec 0< "s.p"
    while read line
    do
    set $line
    ((++wkcnt))
    if (($1>0)) [>0: arithmetic syntax error]
    then

    The line is getting read correctly as shown if I do a print $1 after the
    set.

    Actually, since the line in the second case only holds one field,
    it should be possible to get away without doing a set, but I was trying
    to match the other code.

    The first few lines of s.p look like

    16.1299990
    16.7199990
    16.9800000
    16.0000000
    16.9900000

    --
    Robert B. Peirce, Venetia, PA 724-941-6883
    bob AT peirce-family.com [Mac]
    rbp AT cooksonpeirce.com [Office]
     
    Robert Peirce, Feb 8, 2008
    #1
    1. Advertisements

  2. In article <>,
    Robert Peirce <> wrote:

    > Does anybody have any idea why this works:
    >
    > IFS=' '
    > exec 0< "db/s.d"
    > while read line
    > do
    > set $line
    > if (($3>0)) && ((${15}<16))
    > then
    >
    > And this doesn't?
    >
    > exec 0< "s.p"
    > while read line
    > do
    > set $line
    > ((++wkcnt))
    > if (($1>0)) [>0: arithmetic syntax error]
    > then


    Abject apologies for rank stupidity. Each line in the s.p file ends
    with \r\n instead of just \n. It is necessary to replace "set $line"
    with something like p=$(print $line | tr -d '\r'). Then ((p>0)) works
    fine.

    The \r crap is a holdover from Windows.

    --
    Robert B. Peirce, Venetia, PA 724-941-6883
    bob AT peirce-family.com [Mac]
    rbp AT cooksonpeirce.com [Office]
     
    Robert Peirce, Feb 8, 2008
    #2
    1. Advertisements

  3. Okay. Here's a real puzzle and I don't think it has anything to do with
    \r.

    This doesn't work. It hangs at the if statement, which doesn't execute.
    p=$(echo $line | tr -d '\r')
    ((++wkcnt))
    if ((p>0))

    This does work
    p=$(echo $line | tr -d '\r')
    ((++wkcnt))
    #
    if ((p>0))

    As does this
    ((++wkcnt))
    p=$(echo $line | tr -d '\r')
    if ((p>0))

    You need something after ((++wkcnt)) for if to work and that makes no
    sense to me at all.

    --
    Robert B. Peirce, Venetia, PA 724-941-6883
    bob AT peirce-family.com [Mac]
    rbp AT cooksonpeirce.com [Office]
     
    Robert Peirce, Feb 8, 2008
    #3
  4. I was advised to use the ksh built-in read line to read in a really huge
    file. Well, it turns out, probably because ksh is an interpreter, that
    read line, at least as demonstrated by the following script

    #!/bin/ksh
    exec 0< "db/s.p"
    while read line
    do
    print $line >> /dev/null [echo is actually a hair faster]
    done

    takes way, way longer than cat db/s.p. Consequently, unless someone can
    give me a very fast way to use read line, I am going to stick with my
    kludge of splitting s.p into 50,000 line pieces and processing them in
    order.

    --
    Robert B. Peirce, Venetia, PA 724-941-6883
    bob AT peirce-family.com [Mac]
    rbp AT cooksonpeirce.com [Office]
     
    Robert Peirce, Feb 8, 2008
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Jeffrey Rolland

    Installing ksh from AT&T

    Jeffrey Rolland, Mar 11, 2006, in forum: Apps
    Replies:
    5
    Views:
    162
    Warren Oates
    Mar 12, 2006
  2. Replies:
    11
    Views:
    221
    Paul Nevai
    May 30, 2007
  3. Robert Peirce

    Panther and ksh miss-match

    Robert Peirce, Jan 31, 2004, in forum: Misc
    Replies:
    2
    Views:
    130
    Robert Peirce
    Feb 2, 2004
  4. Aaron Davies

    Problem With System Events Scripting--Can't "click at"

    Aaron Davies, Jul 10, 2003, in forum: Programmer Help
    Replies:
    2
    Views:
    343
    John Stewart
    Jul 12, 2003
  5. Robert Peirce

    using cat to get a list to for in sh or in ksh

    Robert Peirce, Feb 6, 2008, in forum: Programmer Misc
    Replies:
    6
    Views:
    433
    Robert Peirce
    Feb 7, 2008
  6. Robert Peirce

    Odd ksh problem

    Robert Peirce, Feb 29, 2008, in forum: Programmer Misc
    Replies:
    5
    Views:
    374
    Robert Peirce
    Mar 2, 2008
  7. Replies:
    5
    Views:
    169
  8. Aaron Davies
    Replies:
    3
    Views:
    201
    John Stewart
    Jul 12, 2003
Loading...