substr

Last edit

Summary: {{{ awk

Changed:

< {{{

to

> {{{ awk

Changed:

< print substr(mystring,2) # remove the first letter
< print substr(mystring,1,length(mystring)-1) # remove the last character
< print substr(mystring,2,length(mystring)-2) # remove both the first and last character

to

> print substr(mystring,2) # remove the first letter
> print substr(mystring,1,length(mystring)-1) # remove the last character
> print substr(mystring,2,length(mystring)-2) # remove both the first and last character


Removing the first and last characters from a string

The following [[script?]] demonstrates how the substr function and length functions can be combined to remove the first and last [[character?]]s from a string:

 BEGIN {
   mystring="knights"
   print substr(mystring,2)                    # remove the first letter
   print substr(mystring,1,length(mystring)-1) # remove the last character
   print substr(mystring,2,length(mystring)-2) # remove both the first and last   character
 }