FEX(1)

πŸ“¦
version 2.0.0 Β· 3 versions
, in epel 10

πŸ’… FEX(1) β€” the field extraction glow-up

okay bestie, welcome to fex, the field extractor from section 1 of the manual. this page is gonna be a whole vibe and also you will learn literally everything, promise πŸ’–


✨ NAME ✨

fex β€” simple and powerful field extraction. that's it, that's the whole name, and yes it is iconic of it to be that brief πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

fex selector ...

🌸 DESCRIPTION 🌸

fex helps you split things by field. the stuff you'd normally do with awk or cut? so much simpler in fex. and there's also stuff in fex you can't do nearly as easily in awk or cut at all β€” main character energy, no cap πŸ‘‘


πŸ’… SELECTOR SYNTAX πŸ’…

the selector syntax looks like this, bestie:

<delimiter><selection>...

the delimiter is a single character that's used to split the input string. simple.

the first delimiter is implied as space ' '. you can specify multiple fields with curly braces and numbers split by commas. also valid inside the curly braces {} are number ranges β€” number ranges are similar to python array slices, split by colon.

the selection is one of the following, and it's what picks which fields get chosen after the delimiter did its little split ✨

  • a single number β€” a single number will select that numbered field. like awk, fields start at 1.

example selecting third field:

% echo "a b c d e" | fex '3'
a b c d

example selecting the second field delimited by slash:

% echo "/home/hello/world" | fex '/2'
hello
  • {N:M} β€” this is a range selection. the syntax for ranges is, in curly braces, N:M, which chooses the fields in range N to M, inclusive 🫢

example selecting first through fourth fields:

% echo "a b c d e" | fex '{1:4}'
a b c d
  • {N,M,...} β€” the syntax for multiple selections is numbers within curly braces.

example selecting first and fifth fields:

% echo "a b c d e" | fex '{1,5}'
a e
  • {range,field,field,range,field} β€” combining the above, you can literally select ranges and individual fields using the {...} syntax by delimiting each selection by comma 😭 it's giving versatility

example selecting fields 1 to 3, and 5: {1:3,5}

% echo "a b c d e" | fex '{1:3,5}'
a b c e
  • {?range,field,...} β€” the {?...} notation turns on 'non greedy' field separation πŸ‘€ the differences here can be shown best by example, first:
% echo "1...2.3.4" | fex '.{1:3}'
1.2.3
% echo "1...2.3.4" | fex '.{?1:3}'
1..

in the first example, fex uses . as delimiter and ignores empty fields. in the second example (non greedy), it does not ignore those empty fields. 🩡

  • /regexp/ β€” the /regexp/ selection will choose only fields that match the given pattern.

example, pulling out words with addr: in it from ifconfig output:

% ifconfig | fex ' /addr:[0-9]/'
addr:127.0.0.1
addr:192.168.0.28

πŸ”₯ EXAMPLES πŸ”₯

🌈 Show the MTU for a given interface

the mtu in ifconfig output looks like mtu:1500. so have fex split by space, then grab fields matching /mtu:/, split by colon, and choose the last field. chain it, bestie πŸ’œ

% ifconfig wlan0 | fex ' /mtu:/:-1'
1500

πŸ“ Parse apache logs

pull the IP address (first field by space) and the path requested (2nd field in "GET <path> ...")

% fex 1 '"2 2' < /b/logs/access
65.57.245.11 /
65.57.245.11 /icons/blank.gif
65.57.245.11 /icons/folder.gif

🧚 SEE ALSO 🧚

Project site: <http://www.semicomplete.com/projects/fex>

Source Code: <https://github.com/jordansissel/fex>


πŸ’Œ CONTACT πŸ’Œ

please send questions to jls@semicomplete.com

file bugs and feature requests at the following URL:

<https://github.com/jordansissel/fex/issues>

alternately, if you prefer email, feel free to file bugs by email. whatever works for you :) 🫢

patches, ideas, and other contributions by many, nice folks. see the CHANGELIST file for who provided what. ⭐


πŸ‘‘ AUTHOR πŸ‘‘

fex was written by Jordan Sissel. slay.


okay that's the whole page, you're officially fluent in fex now πŸ’€βœ¨ go split some fields, you absolute icon πŸ¦‹

this page is from FEX(1), dated 2024-11-26 β€” see you in the man pages, bestie πŸŽ€πŸ’–

πŸ“¦ where this page comes from