Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-26-2013
Registered User
 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Bash command line to strip tar.gz file extension?

What's the command syntax for stripping out the tar.gz file extension in a bash command line (not script file). Thanks!

prompt/> ls *.tar.gz | <what comes here?>
Sponsored Links
    #2  
Old 02-26-2013
Registered User
 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you!
Sponsored Links
    #3  
Old 02-26-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,268
Thanks: 150
Thanked 720 Times in 693 Posts
How about using sed to remove the extension and print:

Code:
ls | grep tar.gz | sed 's/\.tar\.gz//g'

or simply:

Code:
ls *.tar.gz | sed 's/\.tar\.gz//g'

or using parameter substitution:

Code:
for file in *.tar.gz; do echo "${file%.tar.gz}"; done


Last edited by Yoda; 02-26-2013 at 05:45 PM.. Reason: correction: missed first dot
    #4  
Old 02-26-2013
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,601
Thanks: 123
Thanked 717 Times in 600 Posts
Another variation on bipinajith's theme:

Code:
ls | sed -n '/\.tar\.gz$/s///p'

Regards,
Alister
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conundrum - Flexible way to strip extension Spadez Shell Programming and Scripting 3 07-15-2012 09:17 AM
Bash - Loading a command's output line by line into an array Azrael Shell Programming and Scripting 4 09-20-2011 04:42 AM
Bash script to delete file input on command line animesharma UNIX for Dummies Questions & Answers 1 07-21-2011 04:27 AM
Strip one line from 2 blank lines in a file tipsy Shell Programming and Scripting 6 06-23-2008 08:14 AM



All times are GMT -4. The time now is 02:44 AM.