Skip to main content
deleted 22 characters in body; edited tags
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7 

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l 

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

Thanks, Manaswini

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7 

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l 

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

Thanks, Manaswini

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7 

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l 

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7 

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l

echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l 

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

Thanks, Manaswini

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l

echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

Thanks, Manaswini

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7 

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l 

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

Thanks, Manaswini

Source Link
user179309
  • 119
  • 2
  • 2
  • 5

I need the counts of lines between two matching patterns

I have my input like below -

[11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:43 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 200 - 7 [11/Jul/2016:13:40:47 +0000] "POST --" 500 - 7 [11/Jul/2016:13:41:48 +0000] "POST --" 200 - 7 [11/Jul/2016:13:41:49 +0000] "POST --" 500 - 7 [11/Jul/2016:13:42:12 +0000] "POST --" 500 - 7

I want the number of lines between the input 13:40 to 13:41 , in this case a count as 6.

I tried below options

echo sed -n '/^START_TIME/,/^END_TIME/ p' somelogfile.log | wc -l

echo sed -n '/^13:40:43$/,/^13:41:43$/ p' somelogfile.log | wc -l

but I get 1 all the time.

Can someone check and let me know what is going wrong here ?

Thanks, Manaswini