| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |
|

09-30-04, 14:10
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Winston-Salem, NC
Posts: 25
|
|
|
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
|
|

09-30-04, 14:28
|
|
Registered User
|
|
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> |
+-----------------------+
|
|

09-30-04, 14:43
|
|
Registered User
|
|
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
|
|

09-30-04, 14:47
|
|
Registered User
|
|
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> |
+-----------------------+
|
|

09-30-04, 14:51
|
|
Registered User
|
|
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
|
|

09-30-04, 14:56
|
|
Registered User
|
|
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> |
+-----------------------+
|
|

09-30-04, 15:08
|
|
Registered User
|
|
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.
|
|

09-30-04, 15:36
|
|
Registered User
|
|
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
|
|

09-30-04, 15:46
|
|
Registered User
|
|
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> |
+-----------------------+
|
|

09-30-04, 15:53
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Winston-Salem, NC
Posts: 25
|
|
That didn't work. Not sure I did it right, however.
|
|

09-30-04, 16:03
|
|
Registered User
|
|
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
|
|

09-30-04, 16:11
|
|
Registered User
|
|
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:
Quote:
|
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> |
+-----------------------+
|
|

09-30-04, 16:45
|
|
Registered User
|
|
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
|
|

09-30-04, 17:20
|
|
Registered User
|
|
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> |
+-----------------------+
|
|

10-04-04, 13:23
|
|
Registered User
|
|
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|