I know how to remove the extension of a file, when I know it as:
nameis=$(basename $dataset .csv)
but I want to remove any extension without knowing it beforehand, anyone know how to do this?
Any help appreciated, Ted
Click the File tab, click Options, and then click the Add-Ins category. In the Manage box, click COM Add-ins, and then click Go. The COM Add-Ins dialog box appears. In the Add-Ins available box, clear the check box next to the add-in that you want to remove, and then click OK.
Open File Explorer and click View tab, Options. In Folder Options dialog, move to View tab, untick Hide extensions for known file types option, OK. Then you will se file's extension after its name, remove it.
You should be using the command substitution syntax $(command) when you want to execute a command in script/command. name=$(echo "$filename" | cut -f 1 -d '. ')
In bash you can do the following:
nameis=${dataset%.*}
... e.g.:
$ dataset=foo.txt
$ nameis=${dataset%.*}
$ echo $nameis
foo
This syntax is described in the bash man page as:
${parameter%word}
${parameter%%word}
Remove matching suffix pattern. The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the "%" case) or the longest matching pattern (the "%%" case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With