Beruflich Dokumente
Kultur Dokumente
Print the first field out of CSV output from another command
$ head -1 /etc/passwd | cut -d: -f1
root
Print the first, second, and seventh field out of a CSV file
To change the field simply change the numbers after -f separated by a comma.
$ cut -d: -f1,2,7 passwd.bak
root:x:/bin/bash
Print the fourth field and everything after that from a command
This command is pretty handy if you wanted to make a script out of the past few commands you ran.
Convert space to ,
$ head tmpfile
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-29-generic
x86_64)
73 packages can be updated.
10 updates are security updates.
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
$ cut -s -d: -f1-4 tmpfile
root:x:0:0
daemon:x:1:1
bin:x:2:2
sys:x:3:3
sync:x:4:65534
Bytes
Print bytes 1 through 45
$ cut -b1-45 /etc/motd
Welcome to Ubuntu 12.04 LTS (GNU/Linux
3.2.0-
Characters
Print characters 1 through 25
$ cut -c1-25 /etc/motd
Welcome to Ubuntu 12.04
L