Question: Can some one tell me how to post request to a wcf rest service? my code is below

```
TResponse Post<TRequest, TResponse>(string uri, TRequset input){
  HttpClient client = new HttpClient();
  HttpContent content = new ObjectContent<TRequest>(input, new XmlMediaTypeFormatter());
  HttpResponseMessage message = client.PostAsync(uri, content).Result;
  return message.Content.ReadAsAsync<TResponse>().Result;
}

```

but it gives following exception

```
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'text/html'.
Source=System.Net.Http.Formatting

```

and the value of message variable is

```
message {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: Close
Cache-Control: private
Date: Wed, 19 Dec 2012 14:36:32 GMT
Server: ASP.NET
Server: Development
Server: Server/10.0.0.0
X-AspNet-Version: 4.0.30319
Content-Length: 1766
Content-Type: text/html
}}  System.Net.Http.HttpResponseMessage

```

i know wcf rest is deprecated. But can some one pls tell me how to implement this?
thx

Answer: 
This is kind of a hack but just `grep` for the earliest date you want and print all lines after that using `-A` and then pipe to `grep -c xyz`:

```
$ fgrep -A 100 '20121912-08:15:55' file | fgrep -c 'xyz'
2

```

Note: `fgrep` is just fixed string `grep` as you're not using `regex` patterns, it's the same as doing `grep -F`.

As less hacky way would be to use `sed` to print all lines from the date, this way you wouldn't need to make sure the value to `-A` would cover the length of the file:

```
$ sed -n '/20121912-08:15:55/,$p' file | fgrep -c 'xyz'
2

```

This assumes of course you file is in sorted order by timestamps if it's not then:

```
$ sort file | sed -n '/20121912-08:15:55/,$p' | fgrep -c 'xyz'
2

```
Hmmm, quickly written one : 

```
 grep xyz filename | sed -r 's/^([^ ]+).*/ 20121912-08:15:55 <= \1/' | sed -r 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1\3\2/g' | sed 's/[-:]//g' | bc | grep 1 | wc -l

```

It's pretty ugly (I'm not a sed nor command line master) and may probably be shortened, but it's a way to do it. Explanation below : 

```
  grep xyz filename                                  //gets all interseting lines
| sed -r 's/^([^ ]+).*/ 20121912-08:15:55 <= \1/'    //transform them into 
                                                       //comparison with the 
                                                       //date you want
| sed -r 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1\3\2/g' //invert day and month
| sed 's/[-:]//g'                                    //remove separators
| bc                                                 //ask bc result 
| grep 1                                             //get true results only
| wc -l                                              //and finally count them

```

For last line of your example, the steps would give : 

```
20121912-08:20:55 jui uio xyz                  //grep 'xyz'
20121912-08:15:55 <= 20121912-08:20:55         //sed
20121219-08:15:55 <= 20121219-08:20:55         
20121219081555 <= 20121219082055               
1                                              //result from bc

```

HTH