Possible Duplicate:
Best way to remove file extension from a string?
How to rename multiple files by removing the extension?
I have a metric boatload of .txt files I'd like to load into a database.
The tables have the same name as the .txt files, but without the extension.
So I'd like to execute the command
for f in *.txt; do mysql -u root -p -e "LOAD DATA LOCAL INFILE '$f' INTO TABLE $f" -D rn4; done
However, the last $f
is giving me headaches as I want it to only use the name, not the extension.
So for the file piRNA.txt
the command would look like
mysql -u root -p -e "LOAD DATA LOCAL INFILE 'piRNA.txt' INTO TABLE piRNA" -D rn4
How do I do this?
To make the answer useful for others, please do not just give me the command, but please write a line or two about how to extract the name in the general case.