{
  "name": "hard-bash-pipeline",
  "description": "Create a bash script that processes data through a multi-stage pipeline",
  "dataset": "terminal-bench-local",
  "difficulty": "hard",
  "instruction": "There is a CSV file called transactions.csv in the current directory. Create an executable bash script called pipeline.sh that processes the data and writes results to output.txt. The script must:\n\n1. Filter out any lines where the amount is negative (refunds)\n2. Group transactions by category and sum the amounts for each category\n3. Sort categories by total amount in descending order\n4. Output each line as: CATEGORY TOTAL (where TOTAL is rounded to 2 decimal places)\n\nUse standard Unix tools (awk, sort, grep, etc). Do not use Python or other scripting languages.",
  "setup_files": {
    "transactions.csv": "id,date,category,amount\n1,2024-01-15,Electronics,299.99\n2,2024-01-16,Books,24.99\n3,2024-01-16,Electronics,-49.99\n4,2024-01-17,Clothing,89.50\n5,2024-01-18,Books,15.99\n6,2024-01-18,Electronics,599.99\n7,2024-01-19,Clothing,45.00\n8,2024-01-19,Food,32.50\n9,2024-01-20,Food,28.75\n10,2024-01-20,Books,-10.00\n11,2024-01-21,Electronics,149.99\n12,2024-01-21,Food,55.25\n13,2024-01-22,Clothing,120.00\n14,2024-01-22,Books,39.99\n",
    "test_pipeline.py": "import sys\nimport os\n\nif not os.path.isfile('output.txt'):\n    print('ERROR: output.txt not found')\n    sys.exit(1)\n\nwith open('output.txt') as f:\n    lines = [l.strip() for l in f if l.strip()]\n\npassed = 0\nfailed = 0\n\ndef check(desc, got, expected):\n    global passed, failed\n    if got == expected:\n        passed += 1\n    else:\n        print(f\"FAIL {desc}: got '{got}', expected '{expected}'\")\n        failed += 1\n\n# Expected: Electronics=1049.97, Clothing=254.50, Food=116.50, Books=80.97\n# Sorted desc: Electronics, Clothing, Food, Books\nexpected = [\n    'Electronics 1049.97',\n    'Clothing 254.50',\n    'Food 116.50',\n    'Books 80.97'\n]\n\ncheck('number of lines', len(lines), 4)\nfor i, exp in enumerate(expected):\n    if i < len(lines):\n        check(f'line {i+1}', lines[i], exp)\n    else:\n        check(f'line {i+1}', '<missing>', exp)\n\nprint(f'{passed}/{passed+failed} tests passed')\nif failed > 0:\n    sys.exit(1)\n"
  },
  "verify": "cd $BENCH_WORK_DIR && chmod +x pipeline.sh && ./pipeline.sh && python3 test_pipeline.py",
  "timeout": 240000,
  "tags": ["hard", "bash", "data-processing", "pipeline"]
}
