Living in the Shell #23; cut (Cut Text/Fields from Text Streams)
cut
✂️
Cuts/extracts text/fields out of text streams.
⚠️ Index values are one-based.
Cut characters on a range -c
echo "Hello World\!\nGoodbye\!" | cut -c2-5
Takes characters at indices 2 through 5.
ello oodb
Cut characters on a half-limited range -c
echo "Hello World\!\nGoodbye\!" | cut -c3-
Takes characters from indices 3 and afterwards.
llo World! odbye!
Cut fields split by any delimiter -f
& -d
echo "1,20,300\n40,500,6000\n700,8000,90000" | cut -f2,3 -d','
20,300 500,6000 8000,90000
Change fields delimiter --output-delimiter
echo "1,20,300\n40,500,6000\n700,8000,90000" | cut -f1- -d',' --output-delimiter '/'
1/20/300 40/500/6000 700/8000/90000
Invert selection --complement
echo "1,20,300\n40,500,6000\n700,8000,90000" | cut -f2,3 -d',' --complement
1 40 700
About Living in the Shell
Obsessed with doing things in the shell, I’ve decided to share my daily struggles on living in the shell as terse but informative posts.