I can print the first line of a file usingsed -n 1p file.txtI can delete the first line of a file usingsed -i 1d file.txtIs there a way to print-and-delete in sed? Kind of like a FIFO pop() or Perl's shift.
Printing and deleting the first line of a file using `sed`
files;sed
You can use the command w to write some lines to a different output file. On Linux and many other unix variants, /dev/stdout is the program's standard output, which isn't where sed writes with the -i option. If your system doesn't have /dev/stdout or a variant such as /dev/fd/1, you can write to a named pipe.sed -i -e '1 w /dev/stdout' -e '1d' file.txt