1

I have a temp file o2.csv generated in a loop. I want to cut it's 2nd column and paste it to another file g3temp.csv.

paste <(cut -f 2 o2.csv) g3temp.csv > g3temp.csv

this command generates correct output if the write is made to some new file:

paste <(cut -f 2 o2.csv) g3temp.csv > g3new.csv

why is the write to the same file not giving correct result?

1 Answers1

2

This simply is not possible in the shell. When the command is run, > causes the file to be truncated immediately.

The easiest way to do what you want is to use a temporary file:

paste <(cut -f 2 o2.csv) g3temp.csv > tmp && mv tmp g3temp.csv

With the && expression we make sure the second command will be executed just if the former finished successfully.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141