Select specific field
$ cut -d':' -f1 /etc/passwd #f1=field1 #d=delimiter
Multiple feilds
history
| awk '{$1=$1;print}' | cut -d' ' -f2- #remove beginning spaces
and history number , cut -f2- will start printing from 2nd field to last
history | awk '{$1=$1;print}' | cut -d' ' -f1-4 # cut -f1-4 will print from field 1 to 4
$ grep "/bin/bash" /etc/passwd | cut -d':' -f1,6
root:/root
bala:/home/bala
Multiple feilds with defined range
$ grep "/bin/bash" /etc/passwd | cut -d':' -f1-4,6,7
root:x:0:0:/root:/bin/bash
bala:x:1000:1000:/home/bala:/bin/bash
Example: Usage
[root@mx2 ~]# cat rbllist
server=cbl.abuseat.org
server=spamtrap.drbl.drand.net
server=spamguard.leadmon.net
server=ix.dnsbl.manitu.net
server=relays.nether.net
server=rbl.orbitrbl.com
[root@mx2 postfix]# cat rbllist | cut -d'=' -f2 | while read line; do echo $line, ; done
cbl.abuseat.org,
spamtrap.drbl.drand.net,
spamguard.leadmon.net,
ix.dnsbl.manitu.net,
relays.nether.net,
rbl.orbitrbl.com,
No comments:
Post a Comment