Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk substr()

Status
Not open for further replies.

alfie002

Technical User
Mar 3, 2004
121
GB
Dear all,

i have used awk before and never experienced any problems. However, I am using the substr function to extract substrings from a string. Using the following format

substr(string,start_pos,end_post)

start_pos is an integer representing the start position, this works as expected.

however the end_pos is a variable which represents the length of the string minus 1 character, I want to strip of quote marks around the string.

example as follows;

print substr($field_value, 1, length($field_value -1))"

Field_value has the length of the string and I want to strip off 1 character position. However, when I run this code, instead of getting 8 characters returned I get 2 !!! This is weird and I have tried isolating the code but with no joy.

I am running it on solaris 8.

has any one experience this problem.

Thanks

Alf
 
You may try to replace this:
print substr($field_value, 1, length($field_value -1))
with this:
print substr($field_value, 1, length($field_value)-1)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top