Computing.Net > Forums > Unix > Trim and Timestamp

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Trim and Timestamp

Reply to Message Icon

Name: anilcgowda
Date: August 9, 2005 at 14:38:13 Pacific
OS: UNIX
CPU/Ram: 1GB
Comment:

Hi,

I have a script in which I'm getting the record count from header field and rowcount from wc -l. I'm matching header count with my rowcount. But, since the header count has zeros in the beginning, the match is not successful.
Example: Header_count=00025 Row_count=25. Even though both the values are same, due to preceding zeroes, it results with no match. Is there a way to remove the preceding zeroes from this variable?

Also, I want to add the Timestamp at the end of a variable in the script. How to add the timestamp?
Ex. FileName=header_file_TIMESTAMP... I was timestamp in the place of TIMESTAMP in the above filename.

Please guide me in accomplishing these.

Thanks,
Anil



Sponsored Link
Ads by Google

Response Number 1
Name: Luke Chi
Date: August 9, 2005 at 14:47:21 Pacific
Reply:

1. remove the leading 0'S:

HEADER_COUNT=`expr $Header_count + 0`

2. Timestamp:

FileName=header_file_`date '+%y%m%d%H%M%S'`

Luke Chi


0

Response Number 2
Name: Jim Boothe
Date: August 9, 2005 at 15:23:49 Pacific
Reply:

If you compare variables with = (for string compares), then 00025 will not compare same as 25.

But in this case you should be using -eq which is for numerical compares, in which case they will compare equal.


0

Response Number 3
Name: anilcgowda
Date: August 9, 2005 at 15:58:10 Pacific
Reply:

Thanks Luke and Jim. It worked.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Trim and Timestamp

How to trim the string in the file? www.computing.net/answers/unix/how-to-trim-the-string-in-the-file/7703.html

Sort filename pick latest and delete rest www.computing.net/answers/unix/sort-filename-pick-latest-and-delete-rest/8381.html

Copying files www.computing.net/answers/unix/copying-files/7245.html