Stripping out extensions when file has multiple dots in name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stripping out extensions when file has multiple dots in name
Prev   Next
# 1  
Old 05-14-2008
Stripping out extensions when file has multiple dots in name

I posted this already in another thread, but was told that I should create a seperate thread for the following question:

How do I strip the extension when the delimiter might occur multiple times in the filename?

For example:
I have 2 files as input for my script.
test.extension
test.foo.extension

In my script I want to see "test" and "test.foo" as results.
But the following script-snippet gives "test" for both files.
I know this is caused by the -f1 that I use as setting for cut. But I want to know which command I should use so it starts looking for the delim-character from the right i.s.o the left (probably a different command than cut, but which?)
Code:
!/bin/sh

FILE_NAME=$1
if [ ! -r ${FILE_NAME} ]
then
  echo "Could not find file ${FILE_NAME}"
  exit 1
fi

FNAME=`echo "${FILE_NAME}"| cut -f1 -d'.'`

echo "FNAME = ${FNAME}"


TIA
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get file extension with multiple dots

I am trying to get the file extension with file names that could contain multiple dots using shell scripting. I want to find a way using the sed command. Example Filenames: one.dat one.dat.002 Results: dat I would like to return dat in both instances using the sed command. How can I... (4 Replies)
Discussion started by: smkremer
4 Replies

2. Shell Programming and Scripting

List directory name (only once) after multiple file extensions found

Here is a simplified example of my problem. Say I have the following 3 sub-directories; ./folder1 A.txt A.sh ./folder2 B.txt ./folder3 C.txt C.sh I would like to list the directory names which contain both '.txt' & '.sh' type extensions. I have came up with the following code;... (8 Replies)
Discussion started by: mmab
8 Replies

3. Shell Programming and Scripting

Remove filenames beginning with multiple dots

hi all, I want to remove filenames beginning with multiple dots.how I can do this. Thanks in advance (5 Replies)
Discussion started by: sriharsharavi
5 Replies

4. Shell Programming and Scripting

Replacing multiple extensions

HI, I have some csv files with mutiple extensions, I want to remove all the extensions and keep only the .csv extension. anybody can suggest me how to do this. source files 1.txt.csv.txt.csv.csv.txt.csv 2.csv.txt.csv.txt.csv.txt target 1.csv 2.csv --Wang (1 Reply)
Discussion started by: wangkc
1 Replies

5. Shell Programming and Scripting

Replace multiple dots (.) with spaces ( )

Hi all, I have files in the filename pattern of, this.is.the.name.of.my.file.mov and I would like to remove dots (.) and replace them with spaces ( ) so the output would be, this is the name of my file.mov The other issue that I have is that the number of dots (.) in the file... (6 Replies)
Discussion started by: Monkey Dean
6 Replies

6. UNIX for Dummies Questions & Answers

changing extensions for multiple files at once

I copied some files to another folder, and I want to change them from .doc extensions to .txt extensions. I tried using the cp and mv commands, but it didn't work. Is it possible to change file extensions with these commands, and if so how do I do it? I tried using the * wildcard (say cp *.doc... (1 Reply)
Discussion started by: Straitsfan
1 Replies

7. Shell Programming and Scripting

Creating multiple extensions

Friends I want to automat sending a letter to different persons whose directories are named as 001, 002, 003, 004. To push the same letter to all these directories, I need to name the letter as letter.001, letter.002 like that. Is there any method whereby I get the extension of this letter... (2 Replies)
Discussion started by: chssastry
2 Replies

8. Shell Programming and Scripting

Truncate multiple file extensions

Hi, I have files with names like file1.txt.txt.txt.txt and file2.txt.txt.txt.txt.txt............ (random infinite number of .txt exist). how to truncate (mv) their names to ones with single .txt extension like file1.txt and file1.txt ? In other words, how to extract the filename upto first... (12 Replies)
Discussion started by: prvnrk
12 Replies

9. Shell Programming and Scripting

Stripping out the extension of a file name

I have written a shell script and in my script i have a variable filename=myfile.txt now, i want another variable to be defined for which i have to strip out the extension fo the file name, i.e. newvariable= myfile how do i strip out the ".txt" part from my first variable. Any kind of help... (4 Replies)
Discussion started by: ramky79
4 Replies

10. Shell Programming and Scripting

find -regex: matching multiple extensions

I want to use find to locate files with two different extensions, and run a grep on the results. The closest I have gotten is incredibly slow and ugly: for i in `ls -laR|egrep -e '(.js|.css)'`; do find . -name $i -print|xargs grep -H searchBg; done; This method makes my eyes bleed. Help! ;) ... (2 Replies)
Discussion started by: r0sc0
2 Replies
Login or Register to Ask a Question
pthread_attr_init(3T)													     pthread_attr_init(3T)

NAME
pthread_attr_init(), pthread_attr_destroy() - initialize or destroy a thread attributes object SYNOPSIS
PARAMETERS
attr Pointer to the thread attributes object to be initialized or destroyed. DESCRIPTION
initializes a thread attributes object attr with the default value for all the thread attributes. When a thread attributes object is used to create a thread, the values of the individual attributes determine the characteristics of the new thread. Attributes objects act like additional parameters to object creation. A single attributes object can be used in multiple calls to After a thread attributes object has been used to initialize one or more threads, any function affecting the attributes object does not affect the previously created threads. The thread attributes and their default values are: stacksize POSIX.1c does not define a default value. On HP-UX released on PA-RISC platforms, the default is 64K. On HP-UX released on Itanium(R)-based platforms, the default is 256K. guardsize The default value is bytes. stackaddr The default value is NULL. detachstate The default value is contentionscope POSIX.1c does not define a default value. The default value is set to The scope can also be specified externally by using the options listed in the pthread_scope_options(5) manpage. inheritsched POSIX.1c does not define a default value. On HP-UX, the default value is schedpolicy POSIX.1c does not define a default value. On HP-UX, the default value is schedparam POSIX.1c does not define a default value. processor The default value is binding_type The default value is If an initialized thread attributes object is reinitialized, the initialization results in undefined behavior. destroys the thread attributes object attr. The destroyed thread attributes object ceases to exist and its resources are reclaimed. Refer- encing the object after it has been destroyed results in undefined behavior. A destroyed thread attributes object can be reinitialized using thread attribute initialization routine Threads that have already been created using this attributes object are not affected by the destruction of the thread attributes object. RETURN VALUE
Upon successful completion, and return zero. Otherwise, an error number is returned to indicate the error (the variable is not set). ERRORS
If any of the following occur, the function returns the corresponding error number: [ENOMEM] There is insufficient memory available in which to initialize the pthread attributes object. [EINVAL] The value specified by attr is invalid. If any of the following occur, the function returns the corresponding error number: [EINVAL] The value specified by attr is invalid. AUTHOR
and were derived from the IEEE POSIX P1003.1c standard. SEE ALSO
pthread_create(3T). STANDARDS CONFORMANCE
Pthread Library pthread_attr_init(3T)