First page Back Continue Last page Overview Graphics
Handling fields in text files
Get only the first field of your password file
- $ cut -d : -f 1 /etc/passwd
- This tokenizes the file /etc/passwd using : as the delimiter (-d :), and returns the first field (-f 1)
When the delimiter is not easy to establish, use awk
- $ awk '{print $2}' <file>
- This returns the second token of each line of <file>
Notes:
awk is a full-blown text processing interpreted programming language.
http://www.gnu.org/manual/gawk-3.1.1/gawk.html if you feel like scratching more than the surface