Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Run A Command Line Process On All Files In A Directory And Collect The Output Into A New File

The Script

This was a test script for setting up a larger process. It reads all the files in a directory, passes them through a secondary process, then puts all the outputs in a single file :

bash
#!/bin/bash

OUTPATH="results file.txt"
: > "$OUTPATH"

for file in input_dir/*.txt
do
  cat "$file" \
  | tr '[:upper:]' '[:lower:]' \
  >> "$OUTPATH" 
done

Details

Example

Given these three input files :

code fullcode fullcode full

The script will produce :

results full

Footnotes And References