Split string into non alphanumeric characters with awk

I am trying to get the last substring before an alphanumeric character. For example,

1) beta gamma foo

2) beta gamma% foo

3) beta gamma | --- foo

In all the examples above, I am trying to get "foo" as it is the last substring after splitting into non-alphanumeric characters

So far I have tried

cat file* | awk -F'[^:alnum:]' '{print $NF;}' | less

      

but this does not give expected results

+3


source to share


1 answer


Your POSIX regex is wrong. Use this command awk

:



awk -F '[^[:alnum:]]' '{print $NF}' file
foo
foo
foo

      

+2


source







All Articles