From the course: Linux Tips

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Working with text: cut and sort

Working with text: cut and sort - Linux Tutorial

From the course: Linux Tips

Working with text: cut and sort

- [Narrator] Two helpful tools for working with text on Linux are cut and sort. Cut lets us pick out a particular piece of information from a text string, and sort lets us reorder lines of text in particular ways. Let's take a look at cut first. If you're working with a file like a log, or something that has information presented in a predictable way, you can use cut to, well, cut out a predetermined piece of information and return it to you, or send it along to another program. Let's use cut to pull the names of users on our system out of the password file. This might be something you could do as part of a periodic audit of accounts. Let's take a look at the ETC password file again to remind ourselves of how it's formatted. The username here is at the beginning followed by a colon. That colon acts as a delimiter between fields. And with cut, we can use the field position and delimiter to pull out a particular field. All right, cut, dash d, for delimiter, a colon, and dash f and one…

Contents