The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
number of occurences of a string siddu_chittari Shell Programming and Scripting 12 12-04-2006 09:09 PM
$A is a number / any other string? How to determine ? csaha Shell Programming and Scripting 2 02-21-2006 12:03 AM
How to format number/string in ksh GNMIKE Shell Programming and Scripting 2 07-03-2005 12:44 PM
string to number George_king Shell Programming and Scripting 2 09-10-2003 01:48 PM
shell to number and to string xiamin Shell Programming and Scripting 1 11-06-2001 04:59 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2008
Registered User
 

Join Date: Mar 2008
Posts: 2
awk/sed - getting string instead of number

Hi!

I am writing a script handling downloading list of files and I have to check whether file is present locally and if not finished than continue downloading. To do so I have to compare sizes of remote file and local file.

To check remote file size I have to parse something like this:

Code:
Moon:~ jaja$ curl --cookie /tmp/rpd-cookie.txt -I -L -s http://domain.com/path/to/some/file.zip
HTTP/1.1 200 OK
P3P: CP="ALL DSP COR CURa ADMa DEVa TAIa PSAa PSDa IVAa IVDa CONa TELa OUR STP UNI NAV STA PRE"
Date: Mon, 24 Mar 2008 07:49:21 GMT
Accept-Ranges: bytes
Content-Disposition: Attachment; filename=S02E02_20Simpson_20and_20Delilah.mp4
Content-Type: application/octet-stream
Content-length: 80566953
Connection: Keep-Alive
So, in a script I have a line:

Code:
REMOTESIZE=`curl --cookie /tmp/rpd-cookie.txt -I -L -s $1 | grep Content-length | awk '{print $2}'`
But the problem is that I'm getting a string with \r at the end. I tried various combinations, also with tr and sed but no results. Second value, parsed from ls is a valid integer but I can't handle the first one...

Anyone could give me some tip? It's bash-script.

Thanks
hrwath
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-24-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 880
Pipe to sed 's/.$//'
Reply With Quote
  #3 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Mar 2008
Posts: 2
Great!

It works perfect. Thanks a lot.

hrwath
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0