1

I'm super new to using command line so sorry if this seems like a silly question! I'm trying to edit a CSV file in terminal with these set of commands:

(head -n 1 canine_genes_v2.csv && tail -n +2 canine_genes_v2.csv | sort -t, -k2,2n)

sed ‘s/plus/+/g’ canine_genes_v2.csv

sed ‘s/minus/-/g’ canine_genes_v2.csv

cut -d, -f 1,2,3,4,5,6 canine_genes_v2.csv

perl -p -e 's/,/\t/g' canine_genes_v2.csv

My problem is that every time I apply a command it undoes the previous command, I have figured out if I run each command separately and save the output to a different file I'm able to see the change using the md5sum command. But my problem is I want to apply all these commands at the same time to the same file.

Kusalananda
  • 333,661
Yas
  • 11
  • It may also benefit the reader if you put one or two lines of your csv file into your question so we really know what you are looking at. – number9 Oct 09 '21 at 21:56

1 Answers1

1

None of those commands undoes anything, they simply don't change the file at all. Apply one of your commands and see that the file didn't change. Those commands like head, sed and cut read the file, perform their changes and send the output to stdout, e. g. the shell session.

If you want to actually change the file, you could

  • pipe output of one command to the next one
  • use sed with the -i option, if your sed version offers it
  • redirect output of each command to a temporary file with > temp-filename which can be used as input for the next stage
Philippos
  • 13,453