Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Turns out this was mentioned on StackOverflow in 2017.

Here is a sed solution

   sed -i -e1r/dev/stdin -e1N $1
However this still has a limitation. The target file must be more than one line.

Using a named pipe for large files

   test -s 1.fifo||mkfifo 1.fifo

   cat largefile > 1.fifo &

   printf '0r 1.fifo\nw\nq\n'|ed -s $1

   curl -A "" -4o 1.fifo https://example.com/largefile.gz &

   gzip -dc largefile.gz|tail -100|sed -i -e 1r/dev/stdin -e1N $1


Instead of sed -i, one can use ired.

   od -tx1 -An|sed 's/^/w /'|ired -n $1 /dev/stdin
Unless I am mistaken, ired does not use a temp file, unlike sed -i.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: