home

Quickies, by Andrea Olivato

text

Print last position of a splitted string with AWK

I know this is quite easy but I admit I had to look up in google cause I didn’t know awk had lenght function.

#!/bin/bash

STRING="some,thing,is,splitting,here";
echo $STRING | awk '{split($0,a,","); print a[length(a)]}';

3 years ago

May 15, 2009
Comments (View)
blog comments powered by Disqus