Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25

    Unanswered: convert 4th field in file using another command

    Ok, hopefully I can explain this. Here is my output I have in a file:

    job_name|T_1AAJ650_dq_run__dq_tabl|sig_load@dwat00 1|1096307670
    job_name|T_1AAJDAY_dq_cntc_before|sig_load@dwat001 |1096307672
    job_name|T_1AAJDAY__logs_clnt_cnt|sig_load@dwat001 |1096307673
    job_name|D_1AAJ650_dq_run_dq_tabl|sig_load@dwad001 |1096307962

    I want to take the 4th column (the one with the numbers 109*) and convert that into a different format, but still keep it in the 4th column. The number will not always start with 109.

    This command converts that number:

    time0 -A 1096307670

    Output= External Time: 09/27/2004 13:54:30

    I am currently doing this to convert them all:

    get_autotrack_info | nawk -F'|' '{print $4}' > /tmp/temptime

    cat /tmp/temptime | while read time
    do
    time0 -A $time | awk '{print $3,$4}' | sed '1,1d'
    done

    The problem is, I can convert all the numbers, but then my output is ONLY those converted numbers. I want to look at the data above and convert those 109 numbers with the time0 command and still keep them in the 4th column.

    Any advice?

    Thanks,
    Jeff

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by normanjr29
    Ok, hopefully I can explain this. Here is my output I have in a file:

    job_name|T_1AAJ650_dq_run__dq_tabl|sig_load@dwat00 1|1096307670
    job_name|T_1AAJDAY_dq_cntc_before|sig_load@dwat001 |1096307672
    job_name|T_1AAJDAY__logs_clnt_cnt|sig_load@dwat001 |1096307673
    job_name|D_1AAJ650_dq_run_dq_tabl|sig_load@dwad001 |1096307962

    I want to take the 4th column (the one with the numbers 109*) and convert that into a different format, but still keep it in the 4th column. The number will not always start with 109.

    This command converts that number:

    time0 -A 1096307670

    Output= External Time: 09/27/2004 13:54:30

    I am currently doing this to convert them all:

    get_autotrack_info | nawk -F'|' '{print $4}' > /tmp/temptime

    cat /tmp/temptime | while read time
    do
    time0 -A $time | awk '{print $3,$4}' | sed '1,1d'
    done

    The problem is, I can convert all the numbers, but then my output is ONLY those converted numbers. I want to look at the data above and convert those 109 numbers with the time0 command and still keep them in the 4th column.

    Any advice?

    Thanks,
    Jeff

    not tested, but should get you started:
    Code:
    get_autotrack_info | nawk -F'|' '
      BEGIN {
         OFS=FS
         cmdT="time0 -A "
      }
      {
         cmd= cmdT $4
         cmd | getline $4
         close(cmd)
         print 
    }'
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    Quote Originally Posted by vgersh99
    not tested, but should get you started:
    Code:
    get_autotrack_info | nawk -F'|' '
      BEGIN {
         OFS=FS
         cmdT="time0 -A "
      }
      {
         cmd= cmdT $4
         cmd | getline $4
         close(cmd)
         print 
    }'
    My output now looks like this:

    job_name|T_1PRDDNS401|atlas@ucdt003|
    job_name|T_1PRDWCAA33|atlas@ucdt003|

    It's just taking off the 4th column. Any ideas?

    Thanks,
    Jeff

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    hm...... strange. try and post the results:

    Code:
    get_autotrack_info | nawk -F'|' '
      BEGIN {
         OFS=FS
         cmdT="time0 -A "
      }
      {
         cmd= cmdT $4
         cmd | getline cmdO
         close(cmd)
         $4=cmdO
         print 
    }'
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  5. #5
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    Same output, the 4th column is still left off:

    job_name|D_1DPR_monthly_spools|dprofile@cvdd007|
    job_name|D_1DPR_MP_CAN_delete|dprofile@cvdd007|
    job_name|D_1DPR_MP_spool_CANs|dprofile@cvdd007|

    Jeff

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by normanjr29
    Same output, the 4th column is still left off:

    job_name|D_1DPR_monthly_spools|dprofile@cvdd007|
    job_name|D_1DPR_MP_CAN_delete|dprofile@cvdd007|
    job_name|D_1DPR_MP_spool_CANs|dprofile@cvdd007|

    Jeff
    Code:
    get_autotrack_info | nawk -F'|' '
      BEGIN {
         OFS=FS
         cmdT="time0 -A "
      }
      {
         cmd= cmdT $4
         cmd | getline cmdO
         close(cmd)
         print cmdO
    }'
    what is the the "command" you need to run to substitute the 4th column - "time0 -A" ?

    If the above does not work, put an absolute pathname to "time0 -A " in the "cmdT" and see if it helps.

    Post the results.
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  7. #7
    Join Date
    Jul 2004
    Posts
    45

    convert 4th field in file using another command

    As you read the input file store the first 3 fields in a variable (in while loop)
    var1=`echo $line |cut -f1-3 -d'|' `
    and for the forth field
    var2=`echo $line |cut -f4 -d'|'
    pass it as an argument to your command,
    time $var2
    then with the result concatinate with $var1 and write into a newfile
    Is that what you wanted? Looks simple but i am not sure whether thats what you wanted.

  8. #8
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    Now nothing is being returned. Yes, time0 -A is the command. It is recognizing time0.

    Jeff

  9. #9
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by normanjr29
    Now nothing is being returned. Yes, time0 -A is the command. It is recognizing time0.

    Jeff
    well...... it seems you have either of the following problems:
    1. your 4th field is not populated (or your field separator is wrong)
    2. your 'time0 -A' returns nothing given a valid 4th field value
    3. your 'time0 -A whatever' returns its output to srderr - and NOT stdout. Validate that in a simple shell: a=`time0 -A whateverFrom4thField`; echo a=[$a]
    4. or as I said before you need to specify the absolute pathname to time0.

    You'll need to do some debugging yourself as a very similar paradigm works on my system.

    Post the findings, pls
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  10. #10
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    That didn't work. Not sure I did it right, however.

  11. #11
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    Ok, let me try to go through this one by one:

    1. 4th field is populated with data---verified
    2. time0 would definitely return output and it probably is, but it's getting lost somewhere
    3. It writes it to std_out--verified
    4. time0 is in my path and works---verfied
    a=`time0 -A 1096257600`; echo a=[$a]

    a=[ External Time: 09/27/2004 00:00:00]

    I modified this a little to echo $4 and it returns nothing:

    get_autotrack_info | nawk -F'|' '
    BEGIN {
    OFS=FS
    cmdT="time0 -A "
    }
    {
    cmd= cmdT $4
    cmd | getline cmdO
    close(cmd)
    $4=cmdO
    echo $4
    }'

    Give me your little script that you tested this with to see if I can get it to work. It'll probably help me troubleshoot a little. I appreciate all your help.

    Thanks,
    Jeff

  12. #12
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Quote Originally Posted by normanjr29
    Ok, let me try to go through this one by one:

    1. 4th field is populated with data---verified
    2. time0 would definitely return output and it probably is, but it's getting lost somewhere
    3. It writes it to std_out--verified
    4. time0 is in my path and works---verfied
    a=`time0 -A 1096257600`; echo a=[$a]

    a=[ External Time: 09/27/2004 00:00:00]

    I modified this a little to echo $4 and it returns nothing:

    get_autotrack_info | nawk -F'|' '
    BEGIN {
    OFS=FS
    cmdT="time0 -A "
    }
    {
    cmd= cmdT $4
    cmd | getline cmdO
    close(cmd)
    $4=cmdO
    echo $4
    }'

    Give me your little script that you tested this with to see if I can get it to work. It'll probably help me troubleshoot a little. I appreciate all your help.

    Thanks,
    Jeff

    here's a sample "thingy":

    a sample file jeff.txt:
    firstname|lastname|address
    here's the script - jeff.awk:
    Code:
    BEGIN {
       FS=OFS="|"
       cmd="date"
    }
    {
       cmd | getline $(NF+1)
       close(cmd)
       print;
    }
    nawk -f jeff.awk jeff.txt
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  13. #13
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    Quote Originally Posted by vgersh99
    here's a sample "thingy":

    a sample file jeff.txt:


    here's the script - jeff.awk:
    Code:
    BEGIN {
       FS=OFS="|"
       cmd="date"
    }
    {
       cmd | getline $(NF+1)
       close(cmd)
       print;
    }
    nawk -f jeff.awk jeff.txt
    That works for adding `date` to the end of each line, but I need to convert $4 into another format and keep it where it's at. I don't know why this is stumping me so hard.

    Jeff

  14. #14
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    ok, how about this for REPLACING the field - it's basically the same logic.
    I believe you have to debug your time0 invokation and the output. Instead of invoking 'time0 -A' try to invoke 'date' as in my sample and see if it works:

    Code:
    BEGIN {
       FS=OFS="|"
       cmd="date"
    }
    {
       cmd | getline $NF
       close(cmd)
       print;
    }
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  15. #15
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25
    Thanks, but I don't want to just replace the whole column with the same thing. I want to convert that column and keep. An example would be adding quotation marks around the data in the 4th column. The data doesn't change--I've just added to it. That would be somewhat similar to what I'm doing. The numbers wouldn't change, I am just putting them in a different format.

    Thanks for all your help!
    Jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •