Grab certain contents of a file in linux
by sabitha[ Edit ] 2012-06-06 11:53:31
Grab certain contents of a file in linux
cut is used to grab the specific contents of the file. The -d flag specifies the delimiter, and -f specifies which fields to output:
cut -d: -f1 /etc/passwd
The argument to -f can be something like 1,3 to show the first and third fields, or 1-3 to show the first three; there are also -b and -c flags to read bytes and characters instead of fields. If we need something more flexible, then we can use awk like this
cat /etc/passwd | awk -F':' '{print $1}'