I am inexperienced at scripting and am having trouble writing an awk script which takes as input a csv file of the format:
file_name word_text duration
F3F4F4cv_LN !SIL 14.24
F3F4F4cv_LN mmhm 0.149
F3F4F4cv_LN uhhuh 0.214
and makes another csv file identical to the original but with an extra column titled "word_type", e.g.
file_name word_text duration word_type
F3F4F4cv_LN !SIL 14.24 SIL
F3F4F4cv_LN mmhm 0.149 AGR
F3F4F4cv_LN uhhuh 0.214 AGR
The text in the word_type column depends on what text is in the 2nd column, e.g. if "!SIL" in 2nd then "SIL" in 4th, if "mhmm" in 2nd then "AGR" in 4th etc.
I have been trying to do this using the following commands but the loop to open each file in turn isn't working and I am also wondering if there is a more concise way of doing the column addition:
*****
#create a loop to work through a list of files in a directory
for filename in *.csv
do
#create a new text file with an initial row containing the column headings and save as original filename _type:
'BEGIN { print "file_name word_text duration word_type" > filename_type }'
cat filename |' $2~/SIL/ {print $0, "SIL" }' > filename_type
cat filename |'$2~/mmhm/ {print $0, "AGR" }' > filename_type
cat filename |'$2~/uhhuh/ {print $0, "AGR" }' > filename_type
END
done
****************
Any advice would be greatly appreciated as I'm going around in circles!
file_name word_text duration
F3F4F4cv_LN !SIL 14.24
F3F4F4cv_LN mmhm 0.149
F3F4F4cv_LN uhhuh 0.214
and makes another csv file identical to the original but with an extra column titled "word_type", e.g.
file_name word_text duration word_type
F3F4F4cv_LN !SIL 14.24 SIL
F3F4F4cv_LN mmhm 0.149 AGR
F3F4F4cv_LN uhhuh 0.214 AGR
The text in the word_type column depends on what text is in the 2nd column, e.g. if "!SIL" in 2nd then "SIL" in 4th, if "mhmm" in 2nd then "AGR" in 4th etc.
I have been trying to do this using the following commands but the loop to open each file in turn isn't working and I am also wondering if there is a more concise way of doing the column addition:
*****
#create a loop to work through a list of files in a directory
for filename in *.csv
do
#create a new text file with an initial row containing the column headings and save as original filename _type:
'BEGIN { print "file_name word_text duration word_type" > filename_type }'
cat filename |' $2~/SIL/ {print $0, "SIL" }' > filename_type
cat filename |'$2~/mmhm/ {print $0, "AGR" }' > filename_type
cat filename |'$2~/uhhuh/ {print $0, "AGR" }' > filename_type
END
done
****************
Any advice would be greatly appreciated as I'm going around in circles!