There is lots of redundant information stored in memory, e.g FILENAME is stored very often.
I would go for the following, and adapt the END section accordingly:
Code:
{
for (i=1; i<=NF; i++) A[NR,i]=$i
B[NR]=NF
}
FNR==1 {
fc++
fn[fc]=FILENAME
start[fc]=NR
}
END {
for (f=1; f<=fc; f++) {
print fn[f],start[f]
stop=((f+1) in start) ? start[f+1] : NR+1
for (line=start[f]; line<stop; line++) {
print B[line]
}
}
}
Last edited by MadeInGermany; 01-15-2014 at 06:11 AM..
Reason: fix: NR+1. And start[fc] is simply NR.
These 2 Users Gave Thanks to MadeInGermany For This Post:
Hi All,
I have been working on awk and arrays. I have this small script:
cat maillog*|awk -F: '$2=="SMTP-Accept" && $5~/string/ {lastdate=substr($1,1,8); internaluser=$5; v++} END {for (j in v) {print lastdate, v, j}'| sort>> mail.list
This gives me the number of mails users are getting. ... (1 Reply)
Been struggling with a problem, I have been trying to do this in awk, but am unable to figure this out, I think arrays have to be used, but unsure how to accomplish this.
I have a input file that looks like this:
141;ny;y;g
789;ct;e;e
23;ny;n;u
45;nj;e;u
216;ny;y;u
7;ny;e;e
1456;ny;e;g... (3 Replies)
Guys,
OK so i have been trying figure this all all day, i guess its a pretty easy way to do it.
Right, so i have to column of data which i have gotten from one huge piece of data. What i would like to do is to put both of these into one array using awk. Is this possible??
If so could... (1 Reply)
Hi, I've written the following code to manipulate the first 40 lines of a data file into my desired order:
#!/bin/awk -f
{ if (NR<=(4)){
a=a$0" "}
else { if ((NR >= (5)) && (NR <= (13))) {
b=b$0" " }
else {if ((NR >= (14)) && (NR <= (25))){
c=c$0" "}
... (5 Replies)
Hi,
I have spent the afternoon trawling Google, Unix.com and Unix in a Nutshell for information on how awk arrays work, and I'm not really getting too far.
I ahve a batch of code that I am pretty sure can be better managed using awk, but I'm not sure how to use awk arrays to do what I'm... (1 Reply)
Hi,
I have the following data in a file for example:
Name="Fred","Bob","Peterson","Susan","Weseley"
Age="24","30","28","23","45"
Study="English","Engineering","Physics","Maths","Psychology"
Code="0","0","1","1","0"
Name="Fred2","Bob2","Peterson2","Susan2","Weseley2"... (14 Replies)
Hi
Can someone please explain the logic of awk arrays. I have been doing some reading but I dont understand this:
#!/usr/bin/gawk -f
{
arr++;
}
end
{
for(i in arr)
{
print arr,i
}
}
As I understand arr refs the arrays index, so while $2 is a string that cant... (2 Replies)
Hi, buddies
I am new to shell scripting and trying to solve a problem. I read about arrays in awk that they are quite powerful and are associative in nature.
Awk Gurus Please help!
I have a file:
Id1 pp1 0t4 pp8 xy2
Id43 009y black
Id6 red xy2
Id12 new pp1 black
I have... (5 Replies)
I'm a little stuck and would be grateful of some advice!
I have three files, two of which contain reference data that I want to add to a line of output in the third file. I can't seem to get awk to print array contents as I would expect.
The input files are:
# Input file
AAA,OAA,0313... (2 Replies)
Discussion started by: maccas17
2 Replies
LEARN ABOUT PHP
http_persistent_handles_count
HTTP_PERSISTENT_HANDLES_COUNT(3) 1 HTTP_PERSISTENT_HANDLES_COUNT(3)http_persistent_handles_count - Stat persistent handlesSYNOPSIS
object http_persistent_handles_count (void )
DESCRIPTION
List statistics about persistent handles usage.
PARAMETERS RETURN VALUES
Returns persistent handles statistics as stdClass object on success or FALSE on failure.
EXAMPLES
Example #1
A http_persistent_handles_count(3) example
<?php
print_r(http_persistent_handles_count());
?>
The above example will output:
stdClass Object
(
[http_request] => Array
(
[GLOBAL] => Array
(
[used] => 0
[free] => 1
)
)
[http_request_datashare] => Array
(
[GLOBAL] => Array
(
[used] => 1
[free] => 0
)
)
[http_request_pool] => Array
(
)
)
SEE ALSO http_persistent_handles_ident(3), http_persistent_handles_clean(3).
PHP Documentation Group HTTP_PERSISTENT_HANDLES_COUNT(3)