Forrest logo
back to the pv tool

pv:tldr:883ae

pv: Filter a file, see both progress and amount of output data.
$ pv -cN in ${big_text_file} | grep ${pattern} | pv -cN out > ${filtered_file}
try on your machine

This command is used to filter the contents of a big_text_file based on a specific pattern and save the filtered output to a separate file.

Let's break down the command step by step:

  • pv: This is the command-line tool used to monitor the progress of data being passed through a pipeline. It stands for "pipe viewer".

  • -cN: These are pv's options to create and name a custom counter.

  • in ${big_text_file}: This part specifies the input source file that we want to filter. ${big_text_file} represents a placeholder for the actual name or path of the file.

  • |: This is the standard pipe operator in a Unix-like shell, it takes the output of the previous command and feeds it as input to the next command.

  • grep ${pattern}: This command searches for lines in the input that match a specific pattern. ${pattern} represents a placeholder for the pattern you are searching for.

  • |: Another pipe operator to pass the output of the previous command as input to the next command.

  • pv -cN out: Here, pv is used again to create and name another custom counter. This step allows us to monitor the progress of the filtered output.

  • >: This is the output redirection operator. It takes the output of the previous command and redirects it to the specified file.

  • ${filtered_file}: This represents a placeholder for the name or path of the file where the filtered output will be saved.

To summarize, this command reads the content of ${big_text_file}, searches for lines that match ${pattern}, and saves the filtered output to ${filtered_file}. The two instances of pv are used to monitor the progress of the data flowing through the pipeline.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the pv tool