top of page
warssomomacas

Linux Zcat Command Examples For Newbies



True the output of a command is sent to stdout but when piped to xargs, it considered as std in(please read the xargs man page for more information). In the above examples, we have used the pipe character to enable it to read from standard input, which in this case is the output of another command. We will work on the spell checking and general grammar checking. Thanks once again.




Linux zcat Command Examples for Newbies




Normally, files compressed using gzip can be restored to their original form using gzip -d or gunzip commands. What if you want to view the contents of a compressed file without uncompressing it? For this purpose, you need the zcat command utility.


Zcat is a command line utility for viewing the contents of a compressed file without literally uncompressing it. It expands a compressed file to standard output allowing you to have a look at its contents. In addition, zcat is identical to running gunzip -c command. In this guide, we will explain zcat command examples for beginners.


1. The first example shows how to view contents of a normal file using cat command, compress it using gzip command and view the contents of the zipped file using zcat as shown.


In Linux Zcat, Linux ecosystem, we are able to compress the files with the help of gzip or gunzip. But when we need to check the compress file content without uncompressing the compressed files then we are using the zcat command.


zcat: We can use the zcat keyword in the syntax or command. It will take the two-argument as an option and file name. Provide the end result to display the compress file content without uncompressing the file.


The zcat command is majorly working with two components i.e. option and the compressed file name. When any end-user or client will trigger the zcat command? The zcat command will accept the input as an option and compressed file as standard input and display the compress file content as standard output.


Explanation: We are creating a few sample files in the data directory. As per screenshot 1 (a), we have created the data.txt file and compress it with the help of gzip. With the help of the zcat command, we are able to read the compressed file content (refer screenshot 1 (b)). In the same file contented, we are not able to read with normal cat command (refer screenshot 1 (c)).


Explanation: As per the above zcat command, we are able to read the number of compress file at the same time. From the data directory, we are reading the two compress files i.e. data.txt.gz data1.txt.gz at the same time.


zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. zcat will uncompress files whether they have a .gz suffix or not.


In this topic, we will discuss the top 50 most frequently used Linux commands with their examples. These commands are very useful for a beginner and professional both. We have divided these commands into following sections so that you can easily identify their usage:


I used to think I had to uncompress a gzip'd file to work on it with commands like cat, grep, and more, but at some point I learned there were equivalent gzip versions of these same commands, appropriately named zcat, zgrep, and zmore. So, anything you would normally do on a text file with the first three commands you can do on a gzip'd file with the last three commands.


The names of compressed input files are expected to end in.Z, .gz, or .bz2.If a specified input file name does not end in this suffix,zcat searches for a file named file.Z,file.gz, orfile.bz2.For example, if the command line specifies file abc,zcat looks for abc.Z, abc.gz,or abc.bz2.If none of these are found, zcat uses abc with no extension.


For the second issue, we can solve it by utilizing the powerful pipe mechanism inUNIX-like systems. In short, we uncompress the file using zcat, and send thestreamed data to sed for extraction. For example, if the text file is compressed assomefile.tar.gz, then the following command reads line 2, 4, and 6 of the original file:


zcat is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.) zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. zcat will uncompress files that have the correct magic number whether they have a .gz suffix or not.


You can see from the above examples that the general pattern is to feed a list to xargs -i echo to let it print the commands to stdout. The last command after pipe can be sh if you know they run fast, parallel if you want to control the number of concurrent jobs on the same machine, or asub if you want to submit to LSF/SGE. There are also a few variants: e.g. put & or bsub in the echo command. With xargs -i echo, you will not be bound to the parallel grammar. Another advantage is for complex command lines, you can pipe it to more to visually check if the commands are correct. At least for me, I frequently see problems from more before submitting thousands of jobs. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comentarios


bottom of page