sed_multifile
Apply sed patterns to multiple files matching a glob pattern to make targeted text replacements across your codebase or documents.
Instructions
Apply sed pattern to multiple files matching a glob pattern
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Sed pattern to apply | |
| filePattern | Yes | File glob pattern (e.g., "*.ts", "src/**/*.js") | |
| directory | No | Starting directory for search | . |
| backup | No | Create backup files |
Implementation Reference
- src/index.ts:608-644 (handler)Handler implementation for sed_multifile tool. Locates files using 'find' with the given glob pattern, applies the sed pattern via 'perl -i -pe' to each matching file (with optional .bak backups), collects results, and returns a processing summary.case 'sed_multifile': { const { pattern, filePattern, directory = '.', backup = true } = args; // Use find to get files matching pattern const findCmd = `find ${directory} -name "${filePattern}" -type f`; const { stdout: files } = await execAsync(findCmd); if (!files.trim()) { return { content: [{ type: 'text', text: `No files found matching pattern: ${filePattern}` }] }; } const fileList = files.trim().split('\n'); const results = []; for (const file of fileList) { try { const backupExt = backup ? '.bak' : ''; const sedCmd = `perl -i${backupExt} -pe '${pattern}' '${file}'`; await execAsync(sedCmd); results.push(`✓ ${file}`); } catch (error) { results.push(`✗ ${file}: ${error.message}`); } } return { content: [{ type: 'text', text: `Processed ${fileList.length} files:\n${results.join('\n')}` }] }; }
- src/index.ts:67-94 (registration)Registration of the sed_multifile tool in the ListTools response, including name, description, and input schema definition.{ name: 'sed_multifile', description: 'Apply sed pattern to multiple files matching a glob pattern', inputSchema: { type: 'object', properties: { pattern: { type: 'string', description: 'Sed pattern to apply' }, filePattern: { type: 'string', description: 'File glob pattern (e.g., "*.ts", "src/**/*.js")' }, directory: { type: 'string', default: '.', description: 'Starting directory for search' }, backup: { type: 'boolean', default: true, description: 'Create backup files' } }, required: ['pattern', 'filePattern'] } },
- src/index.ts:70-92 (schema)Input schema definition for sed_multifile tool, specifying parameters like pattern, filePattern, directory, and backup options.inputSchema: { type: 'object', properties: { pattern: { type: 'string', description: 'Sed pattern to apply' }, filePattern: { type: 'string', description: 'File glob pattern (e.g., "*.ts", "src/**/*.js")' }, directory: { type: 'string', default: '.', description: 'Starting directory for search' }, backup: { type: 'boolean', default: true, description: 'Create backup files' } }, required: ['pattern', 'filePattern']