First post here. I have something that may prove to be difficult.
I have the following files:
I need to remove the file extensions and store as a variable so they look like this:
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?
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
Personally I don't understand your post or the reasoning behind changing a filename of an archive from one which exists to one which does not exist.
Suggest looking at the -t parameter to tar which when used instead of the -x parameter just lists the files in the archive under their original paths. Thus you can predict the paths in advance.
Please post what Operating System and version you have and what Shell you use.
The space characters around the equals signs in the sample code are not normal syntax in mainstream unix Shell.
Is this pseudo-code (i.e. to explain the process)?
Thank you for the reply. This is the situation. Its all variable driven, but after I extract, I dont know what my folder will be called. I cant CD into it if I dont know what its called.
If this doesnt explain it please say. I really want to get past this problem but Im having a hard time explaining it.
Since I want this to function for any set of URL's which may have two formats like ".tar.gz" or one format ".zip" and may have .'s in the filename like "Python2.3.4" or may not "Nginx", it makes it a bit tricky.
Take a look at the output from this tar command which just lists the contents of the archive.
If you run this and save the output, before running the tar xzf you have a file containing the name of the directory.
This is a general answer because we don't know anything about your Operating System or your Shell. All I can say is that the code posted is a syntax error in every Bourne-type Shell. There is much variation in the tar command.
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)
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)
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)
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)
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)