How to extract part of a file in Linux?
In Linux, you can use the following command to extract part of a file:
- chief
head -n 10 filename
Include the filename of the file to be extracted and use “-n 10” to specify the number of lines to be extracted.
- the rear end of an animal
tail -n 10 filename
In this case, the filename is the name of the file from which content will be extracted, and -n 10 indicates the number of lines to be extracted.
- slice
cut -d ',' -f 2 filename.csv
The filename.csv is the name of the file from which content will be extracted, -d ‘,’ indicates that a comma is used as the delimiter, and -f 2 specifies that content from the 2nd column will be extracted.
- search
grep "keyword" filename
In this case, the filename refers to the name of the file from which content needs to be extracted, and “keyword” is the keyword to be matched.
You can select the appropriate command based on actual needs to extract certain parts of a file.