Curl Command response output has new line and Extra characters

时间:2017-06-15 09:43:54

标签: shell unix curl

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 个答案:

答案 0 :(得分:0)

更新:尝试grep使用Curl输出删除空行,如下所示:

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

Curl还有--output <name>选项将输出重定向到文件。您可以先将响应输出到文件,然后将其用作grep输入:

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