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: 
I'm assuming you want to find the occurrences of pattern: 'xyz' where the date/time value is greater than or equal to a specified date/time: '20121912-08:15:55'. Here's what I'd do using `GNU awk`. Run like:

```
awk -v pattern="xyz" -v time="20121912-08:15:55" -f script.awk file

```

Contents of `script.awk`:

```
BEGIN {
    stamp = convert(time)
}

$0 ~ pattern && convert($1) >= stamp {
    i++
}

END {
    print i
}

function convert(var) {

    x = "(....)(..)(..)-(..):(..):(..)"
    y = "\\1 \\3 \\2 \\4 \\5 \\6"

    return mktime(gensub(x,y,"",var))
}

```

Results:

```
2

```

Alternatively, here's the one-liner:

```
awk -v pattern="xyz" -v time="20121912-08:15:55" 'BEGIN { stamp = convert(time) } $0 ~ pattern && convert($1) >= stamp { i++ } END { print i } function convert(var) { return mktime(gensub(/(....)(..)(..)-(..):(..):(..)/,"\\1 \\3 \\2 \\4 \\5 \\6","",var)) }' file

```
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