0

I'm running a curl command to send data to a remote server. Part of the command is --trace-ascii which shows the full output for curl.

I'm trying to grep this output so I only get the posted data.

This is a sample of the output. I want to capture everything from x-www-form-urlencoded to the first occurrence of <= Recv SSL data

009c: Content-Length: 89
00b1: Content-Type: application/x-www-form-urlencoded
00e2: 
=> Send data, 89 bytes (0059)
0000: site=test&user=admin&description=Loca
0040: l system&location=NWE&site_id=67876&tel
0080: ephone=xxxxxx
== Info: upload completely sent off: 89 out of 89 bytes
<= Recv SSL data, 5 bytes (0x5)
0000: ....J
<= Recv SSL data, 1 bytes (0x1)
0000: .
== Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
<= Recv SSL data, 57 bytes (0x10)

The command I'm using is: echo $OUTPUT | grep -Po '(?<=(x-www-form-urlencoded)).*(?= <= Recv SSL data)'

Which returns data starting at the correct location, but also include all lines containing <= Recv SSL data

I just want:

x-www-form-urlencoded
00e2: 
=> Send data, 89 bytes (0059)
0000: site=test&user=admin&description=Loca
0040: l system&location=NWE&site_id=67876&tel
0080: ephone=xxxxxx
== Info: upload completely sent off: 89 out of 89 bytes

How do I do this ?

Thanks

Update. This is an example of the curl command used:

OUTPUT=`curl -u user:passwprd -s  \
    -d "site=test" \
    -d "user=admin" \
    -d "description=Local system" \
    -d "location=NWE" \
    -d "site_id=67876" \
    -d "telephone=xxxxxx" \
--trace-ascii - -XPOST "https://x.x.x.x/test.php"`

I only want to capture the data posted.

1 Answer 1

3

Your general problem should be the quantifier greediness. With a .*? instead of .* it should work better.

echo $OUTPUT |  grep -Po '(?<=(x-www-form-urlencoded)).*?(?=<= Recv SSL data)'

But I'm surprised your grep worked that good for you. Since grep works per line I would expect it to match nothing.

1
  • Thanks Paul, that seems to have worked. I've updated my original post with how I'm capturing the output. That seems to convert it into a single line.
    – Tom
    Commented Jul 26, 2023 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .