How do I combine two specific adjacent lines in a large text file into one line using sed? For example I want to combine line numbered 2001891 and 2001892 into one line, and write it back to the file at the same line location (meaning line 2001893 and below will get shifted up)?
I’ve googled around for tutorials and manuals on sed but all are too cryptic to me (those '2,3p;N;s/jam.l,21/.,lk;dczA[12]blahblah' means what?)
I am not a
sedguru, but I think you want:(Try it without
-ion a test file before running it on important data, of course.)I tried the simpler
sed '2001891s/\n//', but it doesn’t work when the pattern is\n. For any other pattern (sed '2001891s/a//'for example), it seems to work. It’s too late in the night for me to think about it more, but I hope one of thesedgurus will explain what’s going on with my simplersedcommand.