Bash command line to strip tar.gz file extension? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Bash command line to strip tar.gz file extension?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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
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
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 02-26-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 26 September 2014, 6:37 PM EDT
Location: Galactic Empire
Posts: 3,385
Thanks: 234
Thanked 1,208 Times in 1,134 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
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Another variation on bipinajith's theme:

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

Regards,
Alister
Sponsored Links
Closed Thread

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