The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 02-11-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
input:
Code:
01.02.09 08:30
bob
jill
mark 

01.04.09 07:00
bob 
jill 
mark
tom

01.02.09 09:30
bob
jill
mark 
hj
gh
fm

01.04.09 10:00
bob 
jill 
mark
tom
aaa
bbb
ccc
output:
Code:
01.02.09 08:30 3
01.04.09 07:00 4
01.02.09 09:30 6
01.04.09 10:00 7
code:
Code:
#!/usr/bin/perl
$/="\n\n";
open FH,"<a.txt";
while(<FH>){
	my @temp=split("\n",$_);
	print $temp[0]," ",$#temp,"\n";
}
Code:
awk '/[0-9]*\.[0-9]*\.[0-9]* [0-9][0-9]:[0-9][0-9]/{
	a=$0
	next
}
/^ *$/{
	print a" "n
	n=0
	next
}
{
 n++
}
' a.txt

Last edited by summer_cherry; 02-11-2009 at 11:54 PM..