Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Bash command line to strip tar.gz file extension?

Shell Programming and Scripting


Closed    
 
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: 5 December 2016, 4:51 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 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 06: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 976 Times in 790 Posts
Another variation on bipinajith's theme:

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

Regards,
Alister
Sponsored Links
Closed

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 10:17 AM
Bash - Loading a command's output line by line into an array Azrael Shell Programming and Scripting 4 09-20-2011 05:42 AM
Bash script to delete file input on command line animesharma UNIX for Dummies Questions & Answers 1 07-21-2011 05:27 AM
Strip one line from 2 blank lines in a file tipsy Shell Programming and Scripting 6 06-23-2008 09:14 AM



All times are GMT -4. The time now is 01:41 AM.