Xah Talk Show 2021-11-08 x-bows keyboard, WolframLang for unix grep, emacs xah-wolfram-mode
#!/usr/bin/env wolframscript
executable = $ScriptCommandLine[[1]]
If[Length[$ScriptCommandLine] != 3,
Print["USAGE:"]
Print[executable, " PATTERN PATH"]
Exit[1]
]
pattern = $ScriptCommandLine[[2]]
path = $ScriptCommandLine[[3]]
addIndices[list_] := MapIndexed[{First[#2], #1}&, list]
lines[text_] := StringSplit[text, {"\r\n", "\r", "\n"}] // addIndices
matchingLines[text_] := Select[lines[text], StringContainsQ[#[[2]], pattern]&]
printLine[{number_, contents_}] := Print[number, "\t", contents]
printIfMatch[file_] :=
With[{contents = ReadString[file]},
If[StringContainsQ[contents, pattern],
Print[file]
Scan[printLine, matchingLines[contents]]
Print[]
]
]
FileSystemScan[printIfMatch, path]
xah_talk_show_2021-11-08.txt