Skip to main content
Glama

awk_process

Process files using AWK for column manipulation, calculations, or conditional processing to perform complex operations without full file replacement.

Instructions

Process files using AWK for more complex operations like column manipulation, calculations, or conditional processing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesInput file path
scriptYesAWK script to execute
outputFileNoOutput file path (optional, defaults to stdout)

Implementation Reference

  • The handler implementation for the 'awk_process' tool. It destructures arguments, checks if the input file exists, constructs and executes an awk command line with the provided script, handles output redirection if outputFile is specified, checks for errors in stderr, and returns a response with the processing status or stdout.
    case 'awk_process': { const { file, script, outputFile } = args; if (!existsSync(file)) { throw new Error(`File not found: ${file}`); } let awkCmd = `awk '${script}' '${file}'`; if (outputFile) { awkCmd += ` > '${outputFile}'`; } const { stdout, stderr } = await execAsync(awkCmd); if (stderr) { throw new Error(`AWK error: ${stderr}`); } return { content: [{ type: 'text', text: outputFile ? `Processed ${file} -> ${outputFile}` : stdout || 'AWK processing complete' }] }; }
  • src/index.ts:96-116 (registration)
    The tool registration entry in the tools array provided to server.setTools(). Includes the name, description, and inputSchema defining the expected parameters: file (required string), script (required string), outputFile (optional string).
    name: 'awk_process', description: 'Process files using AWK for more complex operations like column manipulation, calculations, or conditional processing', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'Input file path' }, script: { type: 'string', description: 'AWK script to execute' }, outputFile: { type: 'string', description: 'Output file path (optional, defaults to stdout)' } }, required: ['file', 'script'] } },
  • The input schema defining the parameters for the awk_process tool: required 'file' and 'script' strings, optional 'outputFile' string.
    inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'Input file path' }, script: { type: 'string', description: 'AWK script to execute' }, outputFile: { type: 'string', description: 'Output file path (optional, defaults to stdout)' } }, required: ['file', 'script']
  • The help content string for 'awk_process' tool, providing description, usage examples, and tips, used by the 'help' tool.
    awk_process: `awk_process - AWK script processing ================================= Powerful text processing with AWK. Examples: // Sum second column awk_process({ file: "numbers.txt", script: "{sum += $2} END {print sum}" }) // Process CSV (comma-separated) awk_process({ file: "data.csv", script: "BEGIN{FS=\",\"} {print $1, $3}" }) // Filter and calculate awk_process({ file: "sales.txt", script: "$3 > 100 {count++; total += $3} END {print \"Count:\", count, \"Avg:\", total/count}" }) // Output to file awk_process({ file: "input.txt", script: "{print $2, $1}", outputFile: "reversed.txt" }) Tips: - Use FS for field separator - $1, $2 etc are fields - NR is line number - END block runs after processing `,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MikeyBeez/mcp-smalledit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server