field 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. .TH FIELD 1
  2. .SH NAME
  3. field \- extract fields from tabular data
  4. .SH SYNOPSIS
  5. .B field
  6. [
  7. .B -E
  8. |
  9. .B -e
  10. ]
  11. [
  12. .BI -F regexp
  13. ]
  14. [
  15. .B -0
  16. |
  17. .BI -O seperator
  18. ]
  19. .I field list
  20. [
  21. .I file...
  22. ]
  23. .SH DESCRIPTION
  24. .I Field
  25. extracts and reports fields from tabular data from files. If no files are
  26. specified, data is read from the standard input. The file name `-' also
  27. specifies the standard input.
  28. .PP
  29. The input field separator defaults to one or more whitespace
  30. characters and can be set by the
  31. .B -F
  32. option. The output field separator defaults to a single space character
  33. and can be set to an arbitrary string by the
  34. .B -O
  35. option. If the
  36. .B -0
  37. option is given, fields will be separated by a single NUL character
  38. (binary zero).
  39. .B -O
  40. and
  41. .B -0
  42. are mutually exclusive.
  43. .PP
  44. .B Field
  45. uses a heuristic to decide whether to include empty fields in the output:
  46. if the delimiter is a single character, or a single escaped character, empty
  47. fields will be included. Otherwise, they will be collapsed and empty fields
  48. at the beginning and end of a line will be ignored. This behavior can be
  49. overridden by the
  50. .B -e
  51. or
  52. .B -E
  53. options:
  54. .B -e
  55. will force eliding of empty fields and
  56. .B -E
  57. will force collapsing of empty fields.
  58. .B -E
  59. and
  60. .B -e
  61. are mutually exclusive.
  62. .PP
  63. Fields are selected by number, origin 1. Field 0 is the entire line. Negative
  64. fields count from the end of the line; thus, -1 is the last field. The literal string
  65. `NF' can also be given to specify the last field on the line. Inclusive ranges of
  66. fields can be given by joining the beginning and ending fields with a single `-'
  67. character; if the second number is omitted it is assumed to be NF.
  68. .PP
  69. Multiple fields can be given, separated by whitespace, commas, or the
  70. pipe character.
  71. .PP
  72. Fields can be repeated, and can be specified in arbitrary order. For example:
  73. .PP
  74. .EX
  75. field -F: 2,1,-2-NF /adm/users
  76. .EE
  77. .SH SOURCE
  78. .B /sys/src/cmd/field.c
  79. .SH "SEE ALSO"
  80. .IR awk (1),
  81. .IR cut (1)
  82. .SH BUGS
  83. The range syntax only permits ascending ranges.