#!/bin/bash sed 's/|/ /g' train.txt > train.csv for i in {1..570} do grep "^[0-9]* $i " train.csv > products/p$(printf "%03d" $i) done