cut is a command-line utility that enables us to cut parts of lines from specified files or piped data and print the result to shared output. It can cut parts of a line by a delimiter, byte position, and character.
Along with the
cut command, we have to pass the argument(option) i.e the criteria to filter out the data.
To cut a specific section, it is necessary to specify the delimiter. Delimiters can be a space (' '), a hyphen (-), a slash (/), or anything else.
The following command-line options are used by the cut command to make it more specific:
The cut --version command checks the version.
The cut -c1 filename command gives the list of the first characters of each line in the file.
The cut -c2,4 filename command gives the list of second and fourth characters of each line in the file.
The cut -c1-3 filename command gives the range of characters from the first to the third position of each line in the file.
The cut -c1-3,5-7 filename command gives the list of the range of characters from the first to the third position and fifth to seventh of each line in the file.
The cut -b1-3 filename command gives the list of characters by byte size.
The cut -d: -f 6 /etc/passwd command gives the list of the sixth column separated by delimiter : from the passwd file.
The cut command not only works on a file system, but it can also act on an output of a command. The command ls -l filename | cut -c2-4 shall obtain the range of characters from the second to the fourth position from the output of the ls -l command.
Myself Debomita Bhattacharjee, an IT employee with 6+ years of experience in Software industry. My area of interest is Automation testing and Front End Development.