HXSELECT(1)

πŸ“¦
version 8.8 Β· 2 versions
, in alpine 3.24, arch rolling, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’– HXSELECT(1) πŸ’–

okay bestie, welcome to hxselect β€” part of the ✨ HTML-XML-utils ✨ lineup, and lowkey one of the most useful little gremlins in the whole toolbox. she reads XML, she finds stuff, she prints it. that's the whole vibe. πŸ¦‹


🌸 NAME 🌸

hxselect β€” extract elements or attributes that match a (CSS) selector πŸ’…


✨ SYNOPSIS ✨

hxselect [ -i ] [ -c ] [ -l language ] [ -s separator ] selectors

πŸŽ€ DESCRIPTION πŸŽ€

so basically: hxselect reads a well-formed XML document and outputs all the elements and attributes that match one of the CSS selectors you hand it as an argument. like, it's giving search engine but make it XML. πŸ”₯

for example, this:

hxselect ol li:first-child

selects the first li (list item in XHTML) inside an ol (ordered list). iconic behaviour honestly. πŸ‘‘

if you've got multiple selectors, you gotta separate them with commas. no commas, no party. for example:

hxselect p + ul, blockquote ol

that one selects all ul elements that follow a p, and all ol elements that are descendants of a blockquote element. two-for-one, we love to see it. 🫢

the command operates on the standard input. so pipe it in, bestie. πŸ’Œ

hxselect assumes that class selectors (".foo") refer to an attribute called "class" and that ID selectors ("#foo") refer to an attribute called "id". that's just the rules of the house, no cap. 🏠

the experimental attribute node selector '::attr(name)' is supported, and it selects the attribute of that name. experimental = she's still in beta, be nice to her. πŸ™ˆ

comments and processing instructions? ignored. like, read but never written. they get the silent treatment. πŸ’€


πŸ’… OPTIONS πŸ’…

here's the menu, bestie. every single one:

  • -i β€” match case-insensitively. super useful for HTML and some other SGML-based languages. "A" and "a" are the same girl now. ✨
  • -c β€” print content only. without -c, the start and end tag of the matched element get printed too; with -c, only the contents of the matched element come out. and if you selected an attribute rather than an element (that ::attr() selector from earlier), only the value of the attribute gets printed. minimalism! πŸŽ€
  • -l language β€” sets the default language, for when the root element doesn't have an xml:lang attribute (default: none). example: -l en πŸ‡¬πŸ‡§
  • -s separator β€” a string to print after each match (default: empty). accepts C-like escapes. example: -s '\n\n' to print an empty line after each match. spacing is self-care. 🌈

πŸ¦‹ OPERANDS πŸ¦‹

one operand, and she's the main character:

  • selectors β€” one or more comma-separated selectors. most selectors from CSS level 3 are supported, with the exception of selectors that require interaction (e.g., ':active') or layout (e.g., ':first-line'). so like… hover states? not happening. she doesn't do vibes that need a browser. 😭

πŸ’€ BUGS πŸ’€

okay so here's the tea, and it's a little tragic: case-insensitive selectors (that's the -i option) currently only work for ASCII characters. so "a" matches "A" βœ… but "Γ€" does not match "Γ„" ❌. accented characters, you deserve better. one day. πŸ™


πŸ”₯ SEE ALSO πŸ”₯

go hang out with her friends:


and that's the whole page, bestie!! this is version 7.x, dated 10 Jul 2011 β€” a vintage queen who still eats every single time. go select something gorgeous. mwah. πŸ’–πŸ’…βœ¨