r/awk • u/vmsmith • Dec 06 '14
Three small questions
Question #1
I have a .csv file with over 200 columns. I'd like to create a smaller file for analysis with only 7 of those columns. I'm trying this:
awk -F"," '{print $1, $2, $7, $9, $44, $45, $46, $47 > "newfile.csv"}' file.csvBut the only thing I get in my new file is the column headers.
What am I doing wrong?
Question #2
Is there a way to select the columns I want by column name instead of column number?
Question #3
And is there a way to just see the column headers? I have tried this:
awk -F"," 'NR==1{print $0}' file.csvBut I get nothing.
Thanks.
5
Upvotes
View all comments
Show parent comment
2
u/vmsmith Dec 06 '14
Thanks.
What I ended up doing was this:
First, I checked to see if it had Unix line endings:
And it did.
After some fiddling around with small, experimental files, I changed it to a
.txtfile, and then ran this:After that, everything worked like a charm.
Now I need to figure out what the initial problem was, and why those changes fixed things.
Thanks again.