I am in the bash shell and have a file "data.txt" that includes names and data-points in rows, like this:
bill/bill_data/point1
bill/bill_data/point2
bill/bill_data/point3
frank/frank_data/point1
frank/frank_data/point2
frank/frank_data/point3
etc.
I want to write the data corresponding to each name in separate files. I can do this with grep, but I would like to know why this line does not work:
for i in bill frank; do awk -v name=$i '$0 ~ name' data.txt > data_${i}.txt; done
When I try this, I get an "unexpected newline or end of string" error directed at the end of '$0 ~ name'. I've tried everything I can think of but can't get it to work. Any ideas?
bill/bill_data/point1
bill/bill_data/point2
bill/bill_data/point3
frank/frank_data/point1
frank/frank_data/point2
frank/frank_data/point3
etc.
I want to write the data corresponding to each name in separate files. I can do this with grep, but I would like to know why this line does not work:
for i in bill frank; do awk -v name=$i '$0 ~ name' data.txt > data_${i}.txt; done
When I try this, I get an "unexpected newline or end of string" error directed at the end of '$0 ~ name'. I've tried everything I can think of but can't get it to work. Any ideas?