From e012a9b50fdbb335daaa7c700689ec97a04740f9 Mon Sep 17 00:00:00 2001 From: Mike Holloway Date: Sat, 26 Mar 2022 17:11:58 -0400 Subject: [PATCH] On branch parse-mdls Your branch is up to date with 'origin/parse-mdls'. Changes to be committed: modified: hash-files Write csv columns to csv file. --- hash-files | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/hash-files b/hash-files index b1cc860..63ebed6 100755 --- a/hash-files +++ b/hash-files @@ -63,11 +63,6 @@ hash_files () { create_csv () { #echo "=== Create array of comma-separated-values. === #==================================================" - csv_columns=( "File Path" "File Hash" ) - for key in ${keys_of_interest[@]};do - csv_columns+=( ${keys_of_interest[key]} ) - done - IFS=',';echo "${csv_columns[*]}";IFS=$'\n' # for i in ${!list_of_files[@]}; do # csv_array+=( ${list_of_files[i]},${list_of_hashes[i]} ) # done @@ -78,10 +73,19 @@ create_csv () { write_data () { #echo "=== Write data to a .csv file. === #====================================" + ## Create temp file temp_csv_file=$($mktemp_bin) - printf '%s,%s\n' "File Path" "File Hash" >> $temp_csv_file - for line in ${csv_array[@]};do - printf '%s\n' $line + ## Initialize column names + csv_columns=( "File Path" "File Hash" ) + ## Populate Columns from keys of interest + for key in ${keys_of_interest[@]};do + csv_columns+=( ${keys_of_interest[key]} ) + done + ## Print columns to first line of csv + IFS=',';echo "${csv_columns[*]}";IFS=$'\n' >> $temp_csv_file + ## Print csv array rows following columns row + for row in ${csv_array[@]};do + printf '%s\n' $row done >> $temp_csv_file # cat $temp_csv_file write_log "$temp_csv_file written successfully."