Using awk to cut the last characters of a string

In the example the string is “10987654321” and you want the 5 last characters of a string so “54321”:

Dans l’exemple la chaîne est “10987654321” et on veut les 5 deniers caractères donc “54321” :

#> echo "10987654321" |awk '{print substr($0, length($0)-4)}'
54321

Author: Jey

2 thoughts on “Using awk to cut the last characters of a string

  1. En bash, ça t’évitera un fork
    # toto=12345678
    # echo ${toto:0:4}
    # Et ce que tu veux
    # echo ${toto:${#toto}-5}
    # Ou encore
    # echo ${toto#*4}

    Voir bash expansion

    ++

Leave a Reply

Your email address will not be published. Required fields are marked *