Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unzip a tar.gz file? [duplicate]

Tags:

r

unzip

I wish to download and open the following tar.gz file in R:

http://s.wordpress.org/resources/survey/wp2011-survey.tar.gz

Is there a command which can accomplish this?

like image 574
Tal Galili Avatar asked Aug 22 '11 17:08

Tal Galili


People also ask

How do I unzip a tar gz file?

Simply right-click the item you want to compress, mouseover compress, and choose tar. gz. You can also right-click a tar. gz file, mouseover extract, and select an option to unpack the archive.

How do I unzip a tar file in R?

Extracting files from a tar archive is done with untar function from the utils package (which is included in base R). This will extract all files in "bar. tar" to the "foo" directory, which will be created if necessary. Tilde expansion is done automatically from your working directory.

How do I unzip a tar file?

To extract (unzip) a tar.gz file simply right-click on the file you want to extract and select “Extract”. Windows users will need a tool named 7zip to extract tar.gz files. The -v option will make the tar command more visible and print the names of the files being extracted on the terminal. tar -xvf archive.tar.gz. Copy.

How do I open a tar gz file?

To extract (unzip) a tar.gz file simply right-click on the file you want to extract and select “Extract”. Windows users will need a tool named 7zip to extract tar.gz files.

How do I unzip a GZ file?

You can use the official GNU gzip utility to extract the content of the compressed archive file. If the file you're looking at is a TAR.GZ, using either tar or 7-Zip to extract the file will be a much simpler choice. What Is a GZ File and How Do You Unzip It?

How does tar work with gzip?

To explain a little further, tar collected all the files into one package, community_images.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things: f: this must be the last flag of the command, and the tar f ile must be immediately after. It tells tar the name and path of the compressed file.


1 Answers

fn <- "http://s.wordpress.org/resources/survey/wp2011-survey.tar.gz" download.file(fn,destfile="tmp.tar.gz") untar("tmp.tar.gz",list=TRUE)  ## check contents untar("tmp.tar.gz") ## or, if you just want to extract the target file: untar("tmp.tar.gz",files="wp2011-survey/anon-data.csv") X <- read.csv("wp2011-survey/anon-data.csv") 

Offhand, I don't know of a way to reach into the tar file and read the appropriate csv file without unpacking it ...

like image 84
Ben Bolker Avatar answered Oct 13 '22 21:10

Ben Bolker