Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Bash command line to strip tar.gz file extension?

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-26-2013
ZillaG ZillaG is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 26 February 2013, 5:04 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux 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 Unix and Linux 02-26-2013
ZillaG ZillaG is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 26 February 2013, 5:04 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you!
Sponsored Links
    #3  
Old Unix and Linux 02-26-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 2 July 2015, 12:36 PM EDT
Location: Galactic Empire
Posts: 3,409
Thanks: 240
Thanked 1,217 Times in 1,143 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 Unix and Linux 02-26-2013
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 974 Times in 789 Posts
Another variation on bipinajith's theme:

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

Regards,
Alister
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:20 AM.