1 of 2

If you only have one record per file then this is a simple read loop.


  local first last addr city state zip

  while read -r header data
    case $header in
      FirstName:) first=$data ;;
       LastName:) last=$data ;;
        Address:) addr=$data ;;
           City:) city=$data ;;
          State:) state=$data ;;
            Zip:) zip=$data ;;
               *) echo Ignoring bad line $header $data >&2
  echo "$first,$last,$addr,$city,$state,$zip"

for file in *srcfiles*
  read_data < $file

The read_data function reads each line and splits up the line into a "header" and a "data". Once we get to the end of the file we just print out the results.

We call that function once for each source file via the for loop.

Note some potential gotcha's: If there are commas in the data then this will break things, so you might want to do

  echo "\"$first\",\"$last\",\"$addr\",\"$city\",\"$state\",\"$zip\""

as the output to enclose everything inside "..." layout. If there's any " in the data then this may cause the CSV to be malformed as well.

Adjust the echo line to match the format you want.