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
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI 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
Open "Field Calculator", check "Update existing field", select "NAME" field and use the following expression.
substr("NAME", 0, -4)
Alternatively, one can use the following expression:
regexp_substr("name",'([^.]+)')
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
Inspired by @Matt solution, there is also a special function called base_file_name()
:
base_file_name("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
.
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?