3 ms·
I always thought about writing a GNU/POSIX utility called 'pp' (prepend), that would simply take an input file and insert it above the first line of a target fi
by AdmiralAsshat 6y ago
I always thought about writing a GNU/POSIX utility called 'pp' (prepend), that would simply take an input file and insert it above the first line of a target file. So, essentially, if I have a CSV file without a header and want to quickly insert the header file, I would run:
pp header.txt spreadsheet.csv
And it would be the equivalent of:
cat header.txt spreadsheet.csv > temp
mv temp spreadsheet.csv
But also support all of the expected POSIX niceties, reading from stdin, etc.
But I never got around to it, and it's been a few years since I had to use C at my day-job (which was never great to begin with), so it fell to the wayside.
- dj_mc_merlin 6y agoWhy not just `pp() { echo -e "$(cat $1 $2)" > $2;}`? It can read from stdin just fine.
- jamespwilliams 6y agosponge from moreutils is useful for this, eg cat a b | sponge a
- tyingq 6y agoThe old line editor, ed, is good at this for files. I assume you could tinker a bit to get stdin support. echo -e "0r header.txt\nw" | ed spreadsheet.csv
- tyingq 6y agoReplying to my own post, looks like ex is more straightforward. ex -sc '0r header.txt' -c wq spreadsheet.csv And ugly, but works for stdin: echo "whee" | ex -sc '0r /dev/stdin' -c wq somefile