[LINUX] A memorandum of filter commands that you might forget in an instant

I don't use filter commands at all, so I thought I'd at least summarize them and make them easier to remember, so I'll write them down. ..

filter

A command that receives standard input, performs appropriate processing, and outputs it to standard output. wc If you specify a file as an argument without options, it will display number of lines`` number of words number of bytes.

bash: (optional)

sort It sorts me. If there is no option, it will sort in alphabetical order according to the ASCII code. To be precise, it is just sorted in the order of the character code, so the order is as shown in the example below.

(Example)


A
Z
a
b

(option)


-n Sort in numerical order
-r Sort in reverse order

uniq The basic operation is to display the lines excluding duplicate lines.

(option)


-c Count the number of times a line with the same content appears

cut You can cut out a part of the input

(Format)


cut -d Delimiter-f field number file name

(option)


-d Specifying the delimiter(If not, they are separated by tabs)
-Output only the specified byte on line b
-Display only the specified character number on line c
-f Specify the field number to be displayed
-s Do not output lines that do not contain delimiters

The cut command must select and use only one of -b``-c -f. tr It replaces the characters. Since a file cannot be specified as an argument, it can be used by handling it with an input redirect or by piped the output from an appropriate command.

(How to use)


tr option SET1 SET2

SET1 is the replacement string and SET2 is the replacement string.

(option)


-d Delete the replacement target without replacing
-s Replace the corresponding nth character of SET1 and SET2

(Regular expressions that can be used in SET)


\b backspace
\n line break
\t horizontal tab
a-d Letters a to d in alphabetical order
:cntrl:All control characters
Read help for more information, it was in Japanese

tail Output the last n lines from standard input. If no option is specified, 10 lines will be output.

(option)


-Specify how many lines to output from the end to be displayed with n argument
-f Monitor the file and display it when the content is added
-v Shows the file name at the top

diff It outputs the difference between 2 files. In addition to the default format, there is also a unified format as the output format. I have a habit of reading it, but I won't explain it here. Since git also uses unified format, it is better to output in unified format when using it. By the way, you can also compare directories.

(option)


-q Output only if the contents of the two files are different
-s Output only if the contents of the two files are the same
-u Output in unified format
-a Treat all files as text
-w Ignore all spaces
-b Ignore all space differences
-Z Ignore spaces at the end of lines

Recommended Posts

A memorandum of filter commands that you might forget in an instant
A memorandum that you will often use in Python's Selenium
Linux commands that you often forget
A memorandum of how to write pandas that I tend to forget personally
An app that you must put in Linux
[Linux command] A memorandum of frequently used commands
A memorandum of commands, packages, terms, etc. used in linux (updated from time to time)
An article that gives you a little understanding of the rigid sphere collision algorithm
[Linux] A list of Linux commands that beginners should know
A script that takes a snapshot of an EBS volume
Summary of Linux (UNIX) commands that appeared in Progate
A collection of commands frequently used in server management
A shell program that becomes aho in multiples of 3
If you draw an Omikuji with a probability of 1% 100 times in a row, will you win once?
[Machine learning] Understand from mathematics that standardization results in an average of 0 and a standard deviation of 1.
Here are some grammars that you might get a slapstick face if you know it in Python
Here's a summary of things that might be useful when dealing with complex numbers in Python
A memorandum of kernel compilation
A small memorandum of openpyxl
A story about a magic trick in LT that performs live coding of natural language processing and dependency analysis in an instant from nothing.
A memorandum of using eigen3
A memorandum of filter commands that you might forget in an instant
Personal notes-Memo that you often forget and look up 2016.10
Create code that outputs "A and pretending B" in python
A memorandum that you will often use in Python's Selenium
I wrote a book that allows you to learn machine learning implementations and algorithms in a well-balanced manner.
Linux commands that you often forget
Make a Discord Bot that you can search for and paste images
Create an instance of a predefined class from a string in Python
A function that measures the processing time of a method in python