cancel
Showing results for 
Search instead for 
Did you mean: 

dot filenames

SOLVED
Go to solution
Avery_1
Advisor

dot filenames

how to remove the dot filenames with extension and null extension?

for e.g file.txt to file

file. to file

hey
4 REPLIES
Ramkumar Devanathan
Honored Contributor

Re: dot filenames

hi,

$ basename file.txt ".txt"
$ basename file. "."

The above would work as long as you know the extension.

else, try this -

echo "file.txt" | awk -F '.' '{for (i=1;i
HTH.
- ramd.
HPE Software Rocks!
Avery_1
Advisor

Re: dot filenames

do you know how to use sed in Bourne shell to remove the dot?

hey
Ramkumar Devanathan
Honored Contributor
Solution

Re: dot filenames

Sophia,

this seems to work for me -

$ echo "filename.txt" | sed 's/^\(.*\)\..*/\1/'
filename

$ echo "filename.txt.gz" | sed 's/^\(.*\)\..*/\1/'
filename.txt

In case you are new, it is a common practice to assign points to all responses (0-10 points), on the basis of the helpfulness of the answers.

- ramd.
HPE Software Rocks!
John Meissner
Esteemed Contributor

Re: dot filenames

do you mean a script to rename
file.txt
to
file?

filz=$(ls | grep ".txt")
for i in $filz
do
mv $i $(echo $i | cut -d . -f 1)
done
All paths lead to destiny