הפקודה משמשת לחיתוך שדות פלט עפ"י תוחמים (בעזרתם קובעים באיזה שדות/עמודות יתבצע החיתוך). כאמור ההסברים לקוחים מהפאלם האישי ולכן כתובים באנגלית
The cut command has the ability to cut out characters or fields.
cut use delimiters to determine where to split the fields.
By default, cut's delimiters are stored in the shell variable IFS (Input Field Separators).
Typing:
set | grep IFS
will show what the separator characters currently are; at present, IFS is either:
a. tab
b. new line
c. space.
Usage:
cut [-d char] [-c|-f] list [files...]
-d: define field delimiter (tab by default)
-c list: cut by column position
-f list: cut by field number
Examples:
cat /etc/passwd | cut -d: -f1,7
or:
cut -d: -f1,7 /etc/passwd
will display:
field 1 (username)
field 7 (default shell)
from /etc/passwd.
cut -d: -f1,6-7 /etc/passwd
will display:
field 1 (username)
field 6 (home directory)
field 7 (default shell)ut
who | cut -d' ' -f1
will display the username that
currently login to the system
cut -c1-7 /etc/tstab
will display the first 7 characters
in /etc/fstab (for each line)
בהחלט אחת הפעולות שאני משתמש בהם רבות
כמובן לזה מצטרף פעמים רבות גם:
awk {'print $3'}
a (האות כדי לישר את הטקסט)אני משתמש בשניהם בצורה רבה
סיפרו לי כי ניתן לשלב בין השניים ואז לקצר את הכתיבה ולהוציא קודים יותר אפקטיבים.