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!

Getting first line and other lines with awk 1

Status
Not open for further replies.

Mag0007

MIS
Feb 15, 2005
829
US
Code:
Linux 2.6.14-1.1637_FC4 (localhost.localdomain)         01/14/2006

12:00:01 AM       CPU     %user     %nice   %system   %iowait     %idle
12:10:01 AM       all      0.30      0.00      0.06      0.10     99.54
12:20:01 AM       all      0.13      0.00      0.04      0.02     99.82
12:30:01 AM       all      0.14      0.00      0.04      0.08     99.73
12:40:01 AM       all      0.04      0.00      0.05      0.01     99.91
12:50:01 AM       all      0.11      0.00      0.03      0.00     99.86
01:00:01 AM       all      0.03      0.00      0.02      0.13     99.81
01:10:01 AM       all      0.10      0.00      0.04      0.01     99.86

I have this sample sar data, and I would like to get the Date value into a variable, and also the other data.

To get the date value, I am doing something like this:
Code:
sar | head -n1 | awk {'print $4'}

To get the other values I am doing something like this:

sar | awk {'print "INSERT INTO stats (tme\,usr\,nice\,system\,iowait\,idle)""VALUES \n (\47" $1" "$2 "\47" "\,"$4"\,"$5"\,"$6"\,"$7"\,"$8" );" '}

Is there a way to get the Date value into my second awk statment?
I would like to include Date into the SQL query too...

TIA
 
Example
Code:
sar | awk 'NR==1 { date = $NF }
  NF==8 && $8 ~ /[0-9]/ { print date,$8 }'


--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top