Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help - how to replace final field in record

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I'm running on the following:

Code:
bpdbjobs -report -most_columns | awk -F',' {'print $4, $5, $6, $7, $1, $9'} | grep -v ^[0,1]

my output is this:


54 abc Full xyz 36615 1168136491
54 abc Full xyz 36582 1168088618

I want to add on to the command line something that will allow me to manipulate the last field of each record.

so...
Code:
bpdbjobs -report -most_columns | awk -F',' {'print $4, $5, $6, $7, $1, $9'} | grep -v ^[0,1] | sed'/[0-9]*$/`myprogram ${aReferenceToNumberBeingReplaced}'

I want to take that last field on the line, run it through a program, and put the output of that in its place.

final result:

54 abc Full xyz 36615 Sat Jan 6 20:21:31 2007
54 abc Full xyz 36582 Sat Jan 6 07:03:38 2007


I'm wondering how I can use awk to do this instead of trying out how to use sed...
 
Hi

If you have [tt]gawk[/tt] and I understand correctly :
Code:
bpdbjobs -report -most_columns | awk -F',' '{[red]$NF=strftime("%c",$NF);[/red]print $4, $5, $6, $7, $1, $9}' | grep -v ^[0,1]
Note that you reversed the order of single quotes ( ' ) and braces ( {} ).

Feherke.
 
I think you understand me Feherke, unforunately I don't have gawk.

in your example:

Code:
bpdbjobs -report -most_columns | awk -F',' '{$NF=strftime("%c",$NF);print $4, $5, $6, $7, $1, $9}' | grep -v ^[0,1]

I guess I cant replace strftime with something like `date` and have the current date replace the last field, ($NF).

I know I can use system() but that only returns me a 0. I would like to be able to use the $NF field in a system command and then replace the $NF field with the output of that system command...


 
Can I replace $9 with a shell variable?
 
Perhaps this ?
Code:
bpdbjobs -report -most_columns | awk -F',' '{print $4, $5, $6, $7, $1, "'"`date`"'"}' | grep -v '^[0,1]'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Kipnep70 said:
have the current date replace the last field
No, then I did not understood it correctly. I thought you want to convert the Unix time from the last field.

Then you need PHV's solution.

And an UUOG police thing :
Code:
bpdbjobs -report -most_columns | awk -F',' '[red]!/^[0,1]/[/red]{print $4, $5, $6, $7, $1, "'"`date`"'"}'
By the way, are you sure you want to include the comma ( , ) character too in that set ?

Feherke.
 
For the UUOG:
bpdbjobs -report -most_columns | awk -F',' '[!]$4!~[/!]/^[0,1]/{print $4, $5, $6, $7, $1, "'"`date`"'"}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How would I include the contents of $9 in the `date` command or in my case it would be:

Code:
bpdbjobs -report -most_columns | awk -F',' '!/^[0,1]/{print $4, $5, $6, $7, $1, "'"`bpdbm -ctime $9`"'"}'

I know the above code will not work.. is there a way to put the contents of field 9 ($9) into the system command?

Thanks,
 
I guess you have to read your awk man pages for the getline function and the | operator ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top