1FEX(1)                                                                  FEX(1)
2
3
4

NAME

6       fex - simple and powerful field extraction
7

SYNOPSIS

9       fex selector ...
10

DESCRIPTION

12       fex helps you split things by field. Common tasks you might do with awk
13       or cut are much simpler in fex, and there are things in fex you can't
14       do nearly as easily in awk or cut.
15

SELECTOR SYNTAX

17       The selector syntax looks like this:
18
19         <delimiter><selection>...
20
21       The delimiter is a single character that is used to split the input
22       string.
23
24       The first delimiter is implied as space ' '. You can specify multiple
25       fields with curly braces and numbers split by commas. Also valid in
26       curly braces {} are number ranges. Number ranges are similar to python
27       array slices, split by colon.
28
29       The selection is one of the following and is used to choose fields
30       split by the delimiter.
31
32       a single number
33           A single number will select that numbered field. Like awk, field
34           start at 1.
35
36           Example selecting third field:
37
38             % echo "a b c d e" | fex '3'
39             a b c d
40
41           Example selecting the second field delimited by slash:
42
43             % echo "/home/hello/world" | fex '/2'
44             hello
45
46       {N:M}
47           This is a range selection. The syntax for ranges is, in curly
48           braces, N:M, which chooses the fields in range N to M, inclusive.
49
50           Example selecting first through fourth fields:
51
52             % echo "a b c d e" | fex '{1:4}'
53             a b c d
54
55       {N,M,...}
56           The syntax for multiple selections is numbers within curly braces.
57
58           Example selecting first and fifth fields:
59
60             % echo "a b c d e" | fex '{1,5}'
61             a e
62
63       {range,field,field,range,field}
64           Combining the above, you can actually select ranges and individual
65           fields using the {...} syntax by delimiting each selection by
66           comma.
67
68           Example selecting fields 1 to 3, and 5: {1:3,5}
69
70             % echo "a b c d e" | fex '{1:3,5}'
71             a b c e
72
73       {?range,field,...}
74           The {?...} notation turns on 'non greedy' field separation. The
75           differences here can be shown best by example, first:
76
77             % echo "1...2.3.4" | fex '.{1:3}'
78             1.2.3
79             % echo "1...2.3.4" | fex '.{?1:3}'
80             1..
81
82           In the first example, fex uses '.' as delimiter and ignores empty
83           fields. In the second example (non greedy), it does not ignore
84           those empty fields.
85
86       /regexp/
87           The /regexp/ selection will choose only fields that match the given
88           pattern.
89
90           Example, pulling out words with 'addr:' in it from 'ifconfig'
91           output:
92
93             % ifconfig | fex ' /addr:[0-9]/'
94             addr:127.0.0.1
95             addr:192.168.0.28
96

EXAMPLES

98       Show the MTU for a given interface
99           The 'mtu' in ifconfig output looks like 'mtu:1500'. So have fex
100           split by space, then grab fields matching /mtu:/, split by colon,
101           and choose the last field.
102
103             % ifconfig wlan0 | fex ' /mtu:/:-1'
104             1500
105
106       Parse apache logs
107           Pull the IP address (first field by space) and the path requested
108           (2nd field in "GET <path> ...")
109
110               % fex 1 '"2 2' < /b/logs/access
111               65.57.245.11 /
112               65.57.245.11 /icons/blank.gif
113               65.57.245.11 /icons/folder.gif
114

SEE ALSO

116       awk(1), cut(1),
117
118       Project site: <http://www.semicomplete.com/projects/fex>
119
120       Source Code: <https://github.com/jordansissel/fex>
121

CONTACT

123       Please send questions to jls@semicomplete.com
124
125       File bugs and feature requests at the following URL:
126
127       <https://github.com/jordansissel/fex/issues>
128
129       Alternately, if you prefer email, feel free to file bugs by email.
130       Whatever works for you :)
131
132       Patches, ideas, and other contributions by many, nice folks. See the
133       CHANGELIST file for who provided what.
134

AUTHOR

136       fex was written by Jordan Sissel.
137
138
139
140                                  2023-07-19                            FEX(1)
Impressum