INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

awk substr()

awk substr()

(OP)
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

RE: awk substr()

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

RE: awk substr()

(OP)
thanks phv,

that worked.

Alf

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close