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
    `,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool processes files using AWK but lacks critical details: whether it modifies files in-place or creates new ones, what permissions or prerequisites are needed, error handling, or output behavior beyond the optional outputFile parameter. For a file-processing tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Process files using AWK') and adds clarifying examples ('for more complex operations like column manipulation, calculations, or conditional processing'). It avoids redundancy and wastes no words, though it could be slightly more structured for readability.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a file-processing tool with AWK scripts, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., success/failure, output content), how errors are handled, or dependencies like AWK installation. For a tool with three parameters and potential side effects, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter semantics beyond what the input schema provides. With 100% schema description coverage, the schema already documents all three parameters (file, script, outputFile) clearly. The description implies file processing and script execution but doesn't elaborate on formats, constraints, or examples. This meets the baseline of 3 since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Process files using AWK for more complex operations like column manipulation, calculations, or conditional processing.' It specifies the verb ('process'), resource ('files'), and scope ('using AWK'), distinguishing it from siblings like sed_edit or perl_edit by focusing on AWK's capabilities for complex operations. However, it doesn't explicitly contrast with all siblings (e.g., line_edit might also handle files).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'more complex operations' but doesn't specify what qualifies as complex or when to choose AWK over other tools like sed_edit or perl_edit from the sibling list. There are no explicit when/when-not instructions or named alternatives, leaving usage context implied at best.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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