Operating System - Linux
1753283 Members
5603 Online
108792 Solutions
New Discussion юеВ

Re: getting fields to print in awk

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

getting fields to print in awk

Guys can you help me with the following:

--> ./asm.ksh as_oracle

Report Run Date
--------------------------
31-JUL-2007 16:23:08

Server
---------------
heidegger

Disk Group Total Mb Free Mb
-------------------- -------- ---------
ASM_DATA 73728 20495
ASM_FLASH 110592 96233

the information i require is:

ASM_DATA,73728,20495
ASM_FLASH,110592,96233

so I have attempted the syntax:

awk 'NR>11 {if ($1~/ASM_DATA/) {OFS=",";print $1,$2,$3}}; {if ($1~/ASM_FLASH/) {OFS=",";print $1,$2,$3}}'

This does work however I want to know if this is the best code to run, as I am learning awk I want to ensure my knowledge is complete.

Thanks

Chris.

hello
5 REPLIES 5
Sandman!
Honored Contributor
Solution

Re: getting fields to print in awk

# awk '/ASM_/ {for(i=1;i<=NF;i++) printf(i
James R. Ferguson
Acclaimed Contributor

Re: getting fields to print in awk

Hi Chris:

Use a 'BEGIN' block to set your OFS; avoid the line-number check and simply match an either/or pattern:

# awk 'BEGIN{OFS=","};{if ($1~/ASM_DATA/||$1~/ASM_FLASH/) {print $1,$2,$3}}'

Regards!

...JRF...
lawrenzo_1
Super Advisor

Re: getting fields to print in awk

thanks chaps,

will will have a play with yours sandman :)

Chris
hello
lawrenzo_1
Super Advisor

Re: getting fields to print in awk

Thanks again,

and I'll rephrase my last comment

I'll have a play with your code sandman!!

Chris
hello
Sandman!
Honored Contributor

Re: getting fields to print in awk

Chris,

Thanks for trying the code I posted though the play on words escapes me ;)