0

I am using below curl command to download file from url. But the output file has new line and extra characters due to which Tiff file getting corrupt.

 curl -k -u Username:Password URL >/Test.Tiff

Sample Test.Tiff has below data

1.
2.
3.IDCFILE87918       
4.II*ÿûÞ©¥zKÿJÛï_]ÿÿÿ÷ÿÞï¹×ëÿ¤ÿO]
5¿ûÕÿÿ¯zê¿ß£0•¿þÛ¯kÚÿ¹5Éöûé_u_éwÕzkJï·_¯¯ßþýuw]í~þžmúºßÿzÈfçúîC7½õëÿÛ¯ô¿Z[6.ý®Úö·4ýý ~«v×ÿº^Ÿ¿í¾Ýÿzuýëÿ÷×]}ûÿõé‰ÿ¿m/KûÿµÛ_ý¾×Oín½}+wýzíýö¿õÿî—7.ékñN¿û­Sߦ=ºì%±N—í¯i_Û¶¬:×·m{
8.ÿ­¶ÿím¿í/ívÒ®ÒP­¯Õ¥¶¿}SÛúì%Ú_kûim­ú«i·V½»
9..Âýt•¿ßoÛ]¦Òý´»KߨaPaa…å87M…VÂúý?ÿa„˜ei

First three lines where line no 1 and 2 is newlines which is coming as ^M through VI editor are extra which should not be there.When i delete first 3 lines and save the file then i am able to open the file.

Let me know how first three lines are getting appended.

1 Answer 1

2

Update: Try greping the Curl output to remove blank lines, like this:

curl -k -u <username>:<password> <url> | grep -v '^$' > /Test.Tiff

Curl also has the --output <name> option to redirect output to a file. You may first output the response to a file and then use it as grep input:

curl -k -u <username>:<password> <url> > curl_out.txt
grep -v '^$' curl_out.txt > Test.Tiff
Sign up to request clarification or add additional context in comments.

2 Comments

You can also use | grep . to remove empty lines.
@peterRepeater: neither grep . nor grep '.' remove empty lines for me. Which grep binary, version and OS are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.