Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
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