Skip to main content
added 143 characters in body
Source Link
Kusalananda
  • 356.6k
  • 42
  • 739
  • 1.1k
grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter out all header lines out from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just deletingextracting all lines from the original file that happen to be identical todifferent from the first line of the file.

Without the process substitution:

head -n 1 file.csv | tee file-new.csv | grep -v -F -x -f /dev/stdin file.csv >>file-new.csv 
grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter all header lines out from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just deleting all lines from the file that happen to be identical to the first line.

grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter out all header lines from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just extracting all lines from the original file that happen to be different from the first line of the file.

Without the process substitution:

head -n 1 file.csv | tee file-new.csv | grep -v -F -x -f /dev/stdin file.csv >>file-new.csv 
deleted 1 character in body
Source Link
terdon
  • 252.9k
  • 69
  • 481
  • 720
grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter all header lines out from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just deleting all lines from the file that happenshappen to be identical to the first line.

grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter all header lines out from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just deleting all lines from the file that happens to be identical to the first line.

grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter all header lines out from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just deleting all lines from the file that happen to be identical to the first line.

Source Link
Kusalananda
  • 356.6k
  • 42
  • 739
  • 1.1k

grep -v -F -x -f <( head -n 1 file.csv | tee file-new.csv ) file.csv >>file-new.csv 

This is using a shell that has process substitutions (<(...)), like bash or zsh, to get the header line from the file using head, write that to a new file with tee, and then filter all header lines out from the original file using grep. The filtered lines are appended to the new file, after the header which was previously written there by tee.

This way of doing it does not depend on what the header actually is. It's just deleting all lines from the file that happens to be identical to the first line.