Sponsored Content
Top Forums Shell Programming and Scripting Conundrum - Flexible way to strip extension Post 302671809 by Spadez on Saturday 14th of July 2012 04:33:38 PM
Old 07-14-2012
Conundrum - Flexible way to strip extension

Hi,

First post here. I have something that may prove to be difficult.

I have the following files:

Code:
Example1.0.0.tar.gz
Example2.tar
Example3.zip
Example4.0.0.0.0.0.bzip2

I need to remove the file extensions and store as a variable so they look like this:

Code:
Example1.0.0
Example2
Example3
Example4.0.0.0.0.0

The way I see it, there are only two ways of doing it. First, is to check the name for certain terms, say ".tar",".gz",".zip" and then have it removed from the name. If this is the best way, is there an efficient and clean way to do this?

The second way I see, is that I get the name without the extension after I unzip it, then store as a variable. So, with my command: tar xzf $FILE_VAR, is there a way to grab the folder that is spat out?

Code:
$File_VAR = Example1.0.0.tar.gz
tar xzf $FILE_VAR 
<code to find out resulting folder name and store as variable>

Output = Example1.0.0

I would really appreciate any help and advice you can give,

Thanks,

James

---------- Post updated at 03:33 PM ---------- Previous update was at 03:26 PM ----------

Sorry, second post. The whole reason I want to do this is because I need to CD into the untarred directory without knowing what it is actually called.

Thing is because I cant get the name without the extension, I dont know the name of the folder that will be output from the untar operation, then I cant CD into it.

I dont want to specify the folder name that it will be untarred into because I have thousands of these to do.

Last edited by Scrutinizer; 07-14-2012 at 05:36 PM.. Reason: quote tags changed to code tags
 

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

umask conundrum

Hi All, i was reading up on a umask question on this forum and have a question on this. the umask value on my home PC running on cygwin is 022. when i create a dir it defaults to permission 755, when i create a file it defaults to 644. Now it starts at 777 for dirs and 666 for files and... (1 Reply)
Discussion started by: Irishboy24
1 Replies

2. Shell Programming and Scripting

Perl:Regex for Search and Replace that has a flexible match

Hi, I'm trying to match the front and back of a sequence. It works when there is an exact match (obviously), but I need the regex to be more flexible. When we get strings of nucleotides sometimes their prefixes and suffixes aren't exact matches. Sometimes there will be an extra letter and... (2 Replies)
Discussion started by: jdilts
2 Replies

3. Shell Programming and Scripting

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?> (3 Replies)
Discussion started by: ZillaG
3 Replies

4. IP Networking

iptables conundrum

Ok, if youre reading this prepare yourself.(debian based os) so im trying to do this routing with ip tables, i need to forward/SNAT traffic from 192.168.111.1 to 10.10.10.250, the 192.x.x.x ips are being shoved into a honeyd like program called inetsim so its offline, 10.10.10.125 is connected... (3 Replies)
Discussion started by: Shocco
3 Replies

5. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies
GPG-ZIP(1)							 GNU Privacy Guard							GPG-ZIP(1)

NAME
gpg-zip - Encrypt or sign files into an archive SYNOPSIS
gpg-zip [options] filename1 [ filename2, ... ] directory1 [ directory2, ... ] DESCRIPTION
gpg-zip encrypts or signs files into an archive. It is an gpg-ized tar using the same format as used by PGP's PGP Zip. OPTIONS
gpg-zip understands these options: --encrypt -e Encrypt data. This option may be combined with --symmetric (for output that may be decrypted via a secret key or a passphrase). --decrypt -d Decrypt data. --symmetric -c Encrypt with a symmetric cipher using a passphrase. The default symmetric cipher used is CAST5, but may be chosen with the --cipher-algo option to gpg. --sign -s Make a signature. See gpg. --recipient user -r user Encrypt for user id user. See gpg. --local-user user -u user Use user as the key to sign with. See gpg. --list-archive List the contents of the specified archive. --output file -o file Write output to specified file file. --gpg gpgcmd Use the specified command gpgcmd instead of gpg. --gpg-args args Pass the specified options to gpg. --tar tarcmd Use the specified command tarcmd instead of tar. --tar-args args Pass the specified options to tar. --version Print version of the program and exit. --help Display a brief help page and exit. EXAMPLES
Encrypt the contents of directory 'mydocs' for user Bob to file 'test1': gpg-zip --encrypt --output test1 --gpg-args -r Bob mydocs List the contents of archive 'test1': gpg-zip --list-archive test1 DIAGNOSTICS
The program returns 0 if everything was fine, 1 otherwise. SEE ALSO
gpg(1), tar(1), The full documentation for this tool is maintained as a Texinfo manual. If GnuPG and the info program are properly installed at your site, the command info gnupg should give you access to the complete manual including a menu structure and an index. GnuPG 2.0.15 2010-07-05 GPG-ZIP(1)
All times are GMT -4. The time now is 09:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy