Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
# be sure to use a different file descriptor (here 4)
while IFS= read line <&4; do
  jobName=$( echo "$line" | cut -f 1 )
  sampleName=$( echo "$line" | cut -f 3 )
  if [[ "$jobName" == "" ]]; then
    sampleName="Undetermined"; jobName="none"
  fi
  echo "job $jobName - sample $sampleName"
done 4< sampleinfo.txt | tee read_line_output.txt

Two final modifications:

  • Strip the header line off the input using anonymous pipe syntax  <(tail -n +2 sampleinfo.txt).
    • This syntax takes the standard output of the expression in parentheses (a sub-shell) and that can be used as input instead of a file
      • 4< <(tail -n +2 sampleinfo.txt) instead of 4< sampleinfo.txt.
  • Save all output from the while loop to a file by piping to tee.

...