Differences

This shows you the differences between two versions of the page.

Link to this comparison view

blog:readdelimfile [2009/11/27 17:53] (current)
Line 1: Line 1:
 +====== Read a Delimited File ======
  
 +How can you read a row in delimited file and get each field value into a separate variable?
 +
 +<code bash>
 +#​!/​usr/​bin/​bash
 +
 +IFS=":"​
 +while read f1 f2 f3; do
 +  echo "​$f1-$f2-$f3"​
 +done < delim.txt
 +</​code>​
 +
 +Using the following input file as a sample:
 +<​code>​
 +field1:​field2:​field3
 +field1a:​field2a:​field3a
 +</​code>​
 +
 +Sample run:
 +<​code>​
 +$ ./delim.sh
 +field1-field2-field3
 +field1a-field2a-field3a
 +</​code>​
 +{{tag>​shell programming}}