Reading a File and Splitting Strings in Bash

Last modified: 
Tuesday, December 29th, 2015

An ad hoc Bash example of reading a file in line by line and splitting each line into an array.

filename="input.dat" 
while read -r line
do
  IFS='|' read -ra ARR <<< "$line"
  script="${ARR[0]}";
  outfile="${ARR[1]}";
  echo "Script $script, Outfile $outfile"
done < "$filename"


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.