Sep 20, 2013

Text Processing Utility - CUT



CUT:
             CUT command is useful for extracting the portion of the text.

Manual Page:

$man cut
or
$man --help

Example:


$cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh

From the above output I am going to get single character from all the rows. $cat /etc/passwd | cut -c1
or
$cut -c1 /etc/passwd


From the above output I am going to extract user names .
$cat /etc/passwd | cut -d':' -f1
root
daemon
bin
..

No comments:

Post a Comment