Xah Talk Show 2025-04-11 Ep642 fsharp, write script to do grep sed

xah talk show 2025-04-11 16712
xah talk show 2025-04-11 16712

fantastic, grok code works, 1 shot.

xah talk show 2025-04-11 fsharp find replace 14f3c
xah talk show 2025-04-11 fsharp find replace 14f3c https://x.com/i/grok/share/LdwnDDAinwj4K1IJ9D8YxkOH7
xah talk show 2025-04-11 14fa2
xah talk show 2025-04-11 14fa2
open System
open System.IO
open System.Text.RegularExpressions

let findAndReplaceInFiles (directory: string) (pattern: string) (replacement: string) =
    // Get all .html files in directory
    let htmlFiles = Directory.GetFiles(directory, "*.html", SearchOption.AllDirectories)

    // Process each file
    for file in htmlFiles do
        try
            // Read file content
            let content = File.ReadAllText file

            // Perform regex replacement
            let updatedContent = Regex.Replace(content, pattern, replacement)

            // Only write if content changed
            if content <> updatedContent then
                File.WriteAllText(file, updatedContent)
                printfn "Updated: %s" file
            else
                printfn "No changes: %s" file

        with
        | ex -> printfn "Error processing %s: %s" file ex.Message

// [<EntryPoint>]
// let main argv =

// Example usage
let directory = @"c:/Users/xah/web/xahlee_info/talk_show/xx/"

// Regex pattern to find

// let pattern = @"(GNU Emacs Lisp Reference Manual)"
// let replacement = "(my book)"

// let pattern = @"((my \w+))"
// let replacement = "($1 \1 mine)"

// <title>Abbrev Expansion (((my book \1 mine)))</title>

// let pattern = @"\(\(\(my (\w+) \1 mine\)\)\)"
// let replacement = "γ€Œ$1 \1」"

let pattern = @" mine"
let replacement = "γ€Œsome」"

findAndReplaceInFiles directory pattern replacement
printfn "Processing complete!"
0