Living in the Shell #23; cut (Cut Text/Fields from Text Streams)
Babak K. Shandiz
Posted on December 24, 2021
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
💖 💪 🙅 🚩
Babak K. Shandiz
Posted on December 24, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.