I have a csv file and I found out that one of the columns is messing up all my script. The table looks like this:
cat table.csv | head -n 4
site_id,x_coordinate,y_coordinate,Starting_year,Ending_year,Year_count,Samling_years,Country
FRDE1,52.19387436,-1.76443004,2002,2016,15,12, DE
FRDE2,50.160917,9.318498,2001,2016,16,14, DE
FRDE3,50.037406,9.428786,2001,2015,15,14, DE
Notice that the last column "Country" has a space before the text!
if I do
awk -F',' '{print $8}' table.csv | head -n 3
, I get
Country
DE
DE
which looks as expected. But if I save that same line in a variable then I get:
VAR=$(awk -F',' '{print $8}' table.csv | head -n 3)
echo $VAR
DEntry
If I do the same with any other column it works well but not with that column! Any other awk process I do on the table gets messed up if that column is on the table. If I remove the table then everything works well. I haven't been able to find out what the problem is and I would like to keep the column.
Any tips are very welcome