Linux and different UNIX-like working techniques have many instruments for processing textual content on the command line. With out these instruments (find complete Linux command list here), we’d be pressured to write down the output of 1 command and kind it into the following so we may isolate the bits we really want and never pipe your complete output into an unexpecting command. The minimize command permits us to chop out the items we want so we will pipe them alongside into the meant instructions.
The minimize command, additionally a part of the POSIX compliance necessities, is very helpful for just a few totally different circumstances. It’s not as sturdy as a few of the different instructions, however it’s very helpful in its personal proper. The minimize command is used for, because the title suggests, reducing textual content. Mostly, I consider, it’s used for reducing data out of textual tables, similar to a CSV file or the output of ps.
Tips on how to use minimize command in Linux?
The overall syntax of minimize is as follows.
minimize OPTION... [FILE]...
It’s not tremendous useful in that type, however we’ll cowl a few the choices which might be generally used.
First, we’ll check out reducing out textual content from a desk utilizing tabs between the columns.
minimize -f 1,5 -d ':'/and so on/passwd
This command will pull columns one and 5, the consumer ID and consumer description fields, from the /and so on/passwd file. Right here we’ve used the -f flag to point the fields we would like. This selection accepts comma separated values or ranges within the type of x-y, the place x is the decrease certain and y the higher.
Moreover, you may mix these choices as carried out beneath. The -d choice is for indicating the delimiter, or the separator, worth. Totally different information use totally different values for this. The /and so on/passwd file makes use of a colon, however a csv file makes use of commas, so it’s very helpful to have the ability to specify a delimiter aside from the default of tab.
minimize -f 1-3,7 -d ':'/and so on/passwd
This will present fields one by means of three, in addition to the seventh.
NOTE: The output of some packages isn’t at all times uniform and can typically have clean fields which is able to trigger minimize to behave unexpectedly. An instance of that is utilizing areas for padding as an alternative of tab characters. This will not be unusual. You may typically cope with this by piping the command output by means of tr earlier than minimize.
tr -s ''''
The tr command is the transposition command. It permits you to simply swap characters in a file, very similar to sed, however not almost as versatile. The tr command’s -s (or –squeeze) choice squeezes all white house right into a single house character. This may be very efficient when utilized in mixture with minimize as a result of it supplies rather more constant delimiting of tabular knowledge.
Generally you need to have the ability to change the delimiter from that used within the enter file, and that’s what the –output-delimiter choice is used for.
minimize -f 1,5 -d ':' --output-delimiter=$'t' /and so on/passwd
Right here we’ve specified tab because the delimiter. As a result of we will’t simply cross a tab character (urgent tab sometimes tells bash to aim autocompletion), we use $’t’ to cross a tab character. This sequence tells bash to flee what’s within the quotations and t is the usual escape sequence for a tab character.
And people are the fundamentals of utilizing minimize. There are some extra options, however you’re not as probably to make use of them in day-to-day work.
Tell us if there are any instruments you want to coated or if there are any you want to coated in additional depth specifically.
Additionally Learn: The Ultimate A To Z List of Linux Commands