-1

I have a .csv file with three columns. I want to keep the first column only. I have been trying to work with a command similar to the one below.

cut -f 1,4 output.csv > output.txt

No matter what I do, my output remains the same- giving me all three columns. Can anyone give me some insight? Thanks!

1 Answers1

-1

read file one line at a time, trim everything right of that first comma:

while read -r line; do echo ${line%%,*}; done < output.csv > output.txt

dick
  • 1
  • 3
    This will be far slower than using `cut`, ignoring the fact that you never told `read` how to use `,` as the field separator. – chepner Jun 28 '21 at 19:23
  • just another way to do it without external process. ```read``` is not required to do any delimiting, parameter expansion takes that task. – dick Jun 28 '21 at 19:46
  • 1
    Sometimes an external process is exactly the right thing to use. – chepner Jun 28 '21 at 20:03