STRFILE(1)

STRFILE(1) πŸ’–

the UNIX System Manager's Manual page, but make it make sense bestie ✨


🌸 NAME 🌸

strfile β€” create a random access file for storing strings

unstr β€” dump strings in pointer order


πŸ¦‹ SYNOPSIS πŸ¦‹

strfile [-iorsx] [-c char] sourcefile [outputfile]
unstr [-c char] datafile[.ext] [outputfile]

πŸ’… DESCRIPTION πŸ’…

okay so listen. strfile reads a file that's full of groups of lines, and those groups are separated by a line that has a single percent % sign on it (or, like, whatever delimiter char you wanna specify instead, we're flexible πŸ’). Then it makes you a data file that has a header structure plus a table of file offsets for every group of lines. and why do we care? because that's what lets you grab the strings at random access. iconic behavior honestly.

If you don't hand it an output file on the command line, the output file is just named sourcefile.dat. easy. no cap.

Now unstr β€” she's the undo button 🫢. Her whole purpose is to undo the work that strfile did. She prints out the strings contained in the sourcefile, which is datafile.ext without its extension, or datafile if no extension is specified (and in that case, bestie, the extension .dat gets added to the name of the datafile) β€” in the order that they're listed in the header file datafile. If you don't specify an outputfile, she prints to standard output; otherwise she prints to the file you specified. and here's the glow-up: unstr can also universally change the delimiter character in a strings file. You can even make sorted versions of input files by using strfile -o and then using unstr to dump them out in the table order. we love a collab πŸ’–


✨ Options ✨

the options are literally as follows:

  • -c char β€” change the delimiting character from the percent sign to char. this one's available for both strfile and unstr. equal opportunity πŸ’…
  • -i β€” ignore case when ordering the strings. uppercase girlies and lowercase girlies, treated the same πŸŽ€
  • -o β€” order the strings in alphabetical order. the offset table will be sorted in the alphabetical order of the groups of lines referenced. any initial non-alphanumeric characters are ignored. this option causes the STR_ORDERED bit in the header str_flags field to be set. (also it now really does sort! it didn't used to. πŸ’€ character development fr)
  • -r β€” randomize access to the strings. entries in the offset table will be randomly ordered. this option causes the STR_RANDOM bit in the header str_flags field to be set. (and really does randomize. she's not faking it ✨)
  • -s β€” run silently; don't give a summary message when finished. no commentary, just vibes 🀫
  • -x β€” note that each alphabetic character in the groups of lines is rotated 13 positions in a simple caesar cypher. this option causes the STR_ROTATED bit in the header str_flags field to be set. note that it does NOT rotate the strings β€” that operation must be performed separately. she's just telling you it's rotated, she's not doing the rotation. πŸ™ˆ

the format of the header is:

#define VERSION 1
unsigned long str_version;  /* version number */
unsigned long str_numstr;   /* # of strings in the file */
unsigned long str_longlen;  /* length of longest string */
unsigned long str_shortlen; /* shortest string length */
#define STR_RANDOM    0x1   /* randomized pointers */
#define STR_ORDERED   0x2   /* ordered pointers */
#define STR_ROTATED   0x4   /* rot-13'd text */
unsigned long str_flags;    /* bit field for flags */
char str_delim;             /* delimiting character */

all fields are written in network byte order. every single one. periodt. πŸ’…


πŸ’€ BUGS πŸ’€

fewer now, one hopes. 😭

but okay, here's the tea: fortunes (text strings) that begin with a blank line appear to be sorted between random letters. this includes ASCII art that contains no letters, and first lines that are solely non-alphanumeric, apparently. I've no idea why this should be. genuinely. not a clue. iykyk 🫠


🌈 OTHER USES 🌈

so like… what can you do with this besides printing sarcastic and obscene messages to the screens of lusers at login or logout? (a noble use, honestly, no notes πŸ’…)

there are some other possibilities. source code for a sample program, randstr, is included with this distribution: randstr splits the difference between unstr and fortune. it reads a single, specified file, and randomly selects a single text string. main character energy honestly πŸŽ€

  1. include strfile.h into a news reading/posting program, to generate random signatures. Tin(1) does something similar, in a much more complex manner.
  2. include it in a game. while strfile doesn't support 'fields' or 'records', there's no reason that the text strings can't be consistent: first line, a die roll; second line, a score; third and subsequent lines, a text message.
  3. use it to store your address book. hell, some of the guys I know would be as well off using it to decide who to call on Friday nights (and for some, it wouldn't matter whether there were phone numbers in it or not).
  4. use it in 'lottery' situations. if you're an ISP, write a script to store login names and GECOS from /etc/passwd in strfile format, write another to send 'congratulations, you've won' to the lucky login selected. the prize might be a month's free service, or if you're AOL, a month free on a real service provider. πŸ”₯

🧚 SEE ALSO 🧚

byteorder(3), fortune(6)


⭐ HISTORY ⭐

the strfile utility first appeared in 4.4BSD. this version was heavily modified, much of it in ways peculiar to Linux. work has since been done to make the code more generic, and has so far been tested to work with SunOS 4.x. more platforms are expected to be supported as work continues. she's evolving πŸ’–πŸ¦‹


and that's the whole page bestie! this one's from the 4th Berkeley Distribution, dated June 9, 1993 [Apr. '97] β€” a classic, an icon, a legend πŸ‘‘πŸ’…βœ¨

mwah πŸ’‹ go forth and randomize your strings 🌸

πŸ“¦ where this page comes from