I imported a shapefile that contains track plots of SGY files into QGIS, and I would like to remove '.sgy' from the file names in the attribute table.

In the image, I've highlighted the section of the filename that I would like to delete in bulk



4 Answers 4


Open "Field Calculator", check "Update existing field", select "NAME" field and use the following expression.

substr("NAME", 0, -4)

enter image description here


Alternatively, one can use the following expression:


it includes the regexp_substr() function.


Another alternative using the file_suffix() function. This expression concatenates a . with the file suffix and replaces it with an empty string.

replace("NAME", '.' || file_suffix("NAME"), '')

QGIS 3.24.0

  • very clever and neat!
    – Taras
    Commented Apr 16, 2022 at 12:24

Inspired by @Matt solution, there is also a special function called base_file_name():


However, for a filename with multiple . (such as my_compressed_file.tar.gz) this only removes the last file extension (.gz). Whereas file_suffix() finds tar.gz.

  • 1
    Looks like I made my edit to include base_file_name at the same time you posted this answer! Would you like to poach my sentence about multiple ., and I can remove it from my answer?
    – Matt
    Commented Apr 16, 2022 at 16:51
  • If you don’t mind I can, I just do not know what is the most honest way in this case :)
    – Taras
    Commented Apr 16, 2022 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.