tech at work


awk trick to split string on last occurence of character

Today I needed to transform some filename on the linux shell - in my case i needed to truncate the filename after the last occurence of a delimiter character.

the filename:  special_file_1.0-12.tar.gz

the result needed: special_file

the awk command to do it:

awk -F_ '{OFS="_";NF--;print $0;}'

Have fun 🙂

Filed under: Linux Leave comment
Comments (2) Trackbacks (0)
  1. this helped me a lot.. thanks for sharing

  2. thank you for sharing, it was really helpful when need

Leave a comment

No trackbacks yet.