2. cut
-
The command
cutextracts a certain column (field) from the input, for example:cut -f 3 distros.txtcut -f 1,3 distros.txtcut -f 1-2,3 distros.txt -
If we want to extract only the year, we can do it like this:
cut -f 3 distros.txt | cut -c 7-10The option
-ctellcutto extract from the line characters, instead of fields (as if each character is a field).cut -f 3 distros.txt | cut -c 7-10,1-2,4-5 -
Another way to get the year would be like this:
expand distros.txt | cut -c 23-The command
expandreplaces tabs by the corresponding number of spaces, so that the year would always start at the position 23. -
When working with fields, it is possible to specify a different field delimiter, instead of the tab. For example:
head /etc/passwdcut -d ':' -f 1 /etc/passwd | headHere we extract the first field from
/etc/passwd.
Download lesson07/part2.cast
Loading asciinema cast...