how to remove last two extensions of a filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to remove last two extensions of a filename
# 1  
Old 07-15-2009
how to remove last two extensions of a filename

hi

how to remove extensions of a file.. suppose i have a filename "gtk2-2.4.13-24.el4.x86_64.rpm" and i want the file name as "gtk2-2.4.13-24.el4" means want to remove last two "." extensions of a file

can anyone help me in this

thanks in advance
srik
# 2  
Old 07-15-2009
try this
Code:
echo "gtk2-2.4.13-24.el4.x86_64.rpm" | sed 's/.x86_64.rpm//'


Last edited by ryandegreat25; 07-15-2009 at 03:24 AM..
# 3  
Old 07-15-2009
hi

hi ryandegreat25

i didn't find the code in ur reply..can u post the code plzz

Regards
srik
# 4  
Old 07-15-2009
sorry, is it specific? you can specify it directly since there's probably a lot of dots (.)
# 5  
Old 07-15-2009
Try:
Code:
basename gtk2-2.4.13-24.el4.x86_64.rpm .x86_64.rpm

# 6  
Old 07-15-2009
hi

hi ryandegreat25

thanks for the reply .. but i have a list of file names in a variable

filename="gtk2-2.4.13-24.el4.x86_64.rpm gtk2-2.4.13-24.el4.srik.hhh.rpm ...etc"
and want the output as gtk2-2.4.13-24.el4 and gtk2-2.4.13-24.el4.srik

in this case i just want to remove the last two extensions of filenames

is it possible to remove the extensions based on last two "." ' s


Regards
srik
# 7  
Old 07-15-2009
Try:
Code:
for i in $filename
do
   basename $i $(echo $i | awk -F"." '{print "."$(NF-1)"."$NF}')
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove spaces in filename

Hi team, Here's a requirement for me. Here are the list of files i have in a unix directory. W 2 A D_2014.csv W 3 A D_2014.csv W 4 A D_2014.csv /home/kmani00-> uname -a AIX sliyyvxx 1 6 00F613E54C00 /home/kmani00-> The file names has to be without spaces as follows. W2AD_2014.csv... (1 Reply)
Discussion started by: kmanivan82
1 Replies

2. Shell Programming and Scripting

Remove the last 9 characters of a filename

Hi All! Please can someone help, I have a dir with the following files: ~-rw-r--r-- 1 emmuser users 2087361 Oct 16 15:50 MPGGSN02_20131007234519_24291.20131007 -rw-r--r-- 1 emmuser users 2086837 Oct 16 15:50 MPGGSN02_20131007233529_24272.20131007 -rw-r--r-- 1 emmuser ... (7 Replies)
Discussion started by: fretagi
7 Replies

3. Shell Programming and Scripting

How to remove sections of a filename?

Hello, I need some help with renaming some files by removing a certain portion of the filename. The current file name is: ABC_2013186197_20130708_203556.95336 I need to remove the 5 digits after the first "_". The new file name should be: ABC_197_20130708_203556.95336 I'm not quite... (5 Replies)
Discussion started by: bbbngowc
5 Replies

4. Shell Programming and Scripting

Remove comments from file with specific file name extensions

Hello Unix board community, I have to program a shell script, but I am a complete noob so I hope I get some help here. The assignment is as follows: The program removes all comments regardless of formatting or language from files with specific file name extensions (php, css, js, ...).... (3 Replies)
Discussion started by: TheZeusMan
3 Replies

5. Shell Programming and Scripting

Remove parts from a filename

I want to remove the beginning and end of a filename and keep the middle. E.g. tempblast7114_1#21110932.out_ the current filename I want it to be called 7114_1#21 only How would I do this?? (3 Replies)
Discussion started by: avonm
3 Replies

6. Shell Programming and Scripting

Remove last character from filename

Hi All, I have different type of file (.txt,.csv,.xml) format in my current directory. My requirement is that I need to remove the last character from the file format. Example count.txt$ csp_rules.csv^ Date.xml~ Need Output: count.txt csp_rules.csv Date.xml How to do that?.... (5 Replies)
Discussion started by: suresh01_apk
5 Replies

7. Shell Programming and Scripting

Change filename extensions..from command line

I want to change the extensions of a folder full of files (some of the files are located in subfolders as well) to another extension, but instead of replacing the files I want the new files to be copied into a newly created folder. Here is the folder structure: /Downloads/3eb... (3 Replies)
Discussion started by: bound4h
3 Replies

8. Shell Programming and Scripting

How to remove numbers from filename

Hi all, Can I edit this script: find . -type f | while read i;do && mv "$i" "${i//abc/}" ;done so that it will not only take out abc from the filename but also take out any numbers that might be in the filename as well. An example would be, Input: filename abc 2009.mov Output:... (7 Replies)
Discussion started by: Monkey Dean
7 Replies

9. UNIX for Dummies Questions & Answers

Remove path from filename

In a foreach loop I end up with $file containing the filename INCLUDING the whole path. I want this reduced to just the filename, but I can't seem to remember how I did it some years back. I am sure I can do it with "sed", but I am pretty sure I have seen a simpler command. Anyone? borgeh (3 Replies)
Discussion started by: borgeh
3 Replies

10. UNIX for Dummies Questions & Answers

remove filename prefix

I've got a bunch of files called oldabc, olddef etc. i want to copy these to be abc, def.... I can do this with file extensions....but can get the logic to work for prefixes. All the files I am interested in have a prefix of 'old'. This loop is no good for me....it looks at the content... (2 Replies)
Discussion started by: peter.herlihy
2 Replies
Login or Register to Ask a Question