0

I have a large amount of data formatted like this:

value1,value2,value3
value1,value2,value3
value1,value2,value3
etc..

I want to know how to pull only value2 from every row and output that result. I'm assuming I would use awk in some way?

3
  • Does any of the first two columns contain embedded commas or newlines (which is allowed in CSV files)? Commented Jul 23, 2019 at 14:56
  • 1
    Is "value2" chosen because of its position or because of its value? Commented Jul 23, 2019 at 15:02
  • There are no embedded commas or new lines, its chosen because of its position Commented Jul 23, 2019 at 17:08

1 Answer 1

5

You can use awk:

awk -F, '{print $2}' file

or cut:

cut -d, -f2 file

or csvcut

csvcut -H -c 2 f | tail -n+2

csvcut has the benefit that it also works if you have the delimiter inside the values, e.g.: value1,"value2,3",value4.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.