Question Details

No question body available.

Tags

bash curl awk sed

Answers (5)

January 8, 2026 Score: 2 Rep: 790,677 Quality: Low Completeness: 50%

You may use this awk script:

awk -F'"|: ' '$1 == "Content-Length" {clen = $2}
/filename=/ {fn = $3}
END {print clen ", " fn}' file

77829730, filename.mp3

Where input file is:

cat file

HTTP/1.1 200 OK Server: CacheHTTPd v1.0 Date: Thu, 08 Jan 2026 19:21:11 +0000 Content-Type: application/octet-stream Content-Length: 77829730 Etag: "f88a7c370819f133ddf3bc4fbb7087f611cce890" Expires: Fri, 09 Jan 2026 01:21:06 +0000 Content-Disposition: attachment; filename="filename.mp3" Accept-Ranges: bytes Content-Transfer-Encoding: binary Connection: close

Note that by using -F'"|: ' we are splitting input line using delimiters : or ".

January 8, 2026 Score: 1 Rep: 208,992 Quality: Low Completeness: 40%

If your curl output always looks exactly as you show then using any POSIX awk you could do:

$ curl ... | awk -v RS= -F'["[:space:]]+' -v OFS=', ' '{print $30, $17}' filename.mp3, 77829730
January 8, 2026 Score: 1 Rep: 14,443 Quality: Low Completeness: 40%

curl could be instructed to output that information too (with expected format)

curl -O -s --write-out "%{filenameeffective}, %{sizedownload}\n" https://example.com/downloads/image.jpg

Result

image.jpg, 513
January 8, 2026 Score: 0 Rep: 38,939 Quality: Medium Completeness: 60%

NOTE: per a comment on another answer it appears OP's direct curl output may contain dos line endinges (\r\n); I've added a gsub() call to remove the \r (overkill for this particular script and effectively a no-op when file size is the last item in the output, or if the input to the awk script does not contain \r characters).

Placing your curl output into my local file named curl.out ...

Another awk approach:

awk ' { gsub("\r","") } # strip \r characters /filename=/ { split($0,a,"[\"]"); fname = a[2]; next } /Content-Length:/ { fsize = $NF; next } END { print fname ", " fsize } ' curl.out

Or if you're piping the curl output to the awk script:

cat curl.out | awk ' { gsub("\r","") } /filename=/ { split($0,a,"[\"]"); fname = a[2]; next } /Content-Length:/ { fsize = $NF; next } END { print fname ", " fsize } '

Or we can put the awk code in it's own file:

$ cat curl.awk { gsub("\r","") } /filename=/ { split($0,a,"[\"]"); fname = a[2]; next } /Content-Length:/ { fsize = $NF; next } END { print fname ", " fsize }

And reference curl.awk on the command line, eg:

awk -f curl.awk curl.out

#### or

cat curl.out | awk -f curl.awk

All of these generate:

filename.mp3, 77829730
January 8, 2026 Score: -1 Rep: 6,769 Quality: Low Completeness: 40%

If your curl output file is called curl.out, the following bash command will help:

echo $(grep '^Content-Disposition:' curl.out | awk -F'"' '{print $2}'), $(grep -i '^Content-Length:' curl.out | awk '{print $2}')