2 ms·
I still use for ed non-interactively moving and deleting lines in large text files, e.g., lists, and have not come across anything that I think is better. I us
by 1vuio0pswjnm7 3y ago
I still use for ed non-interactively moving and deleting lines in large text files, e.g., lists, and have not come across anything that I think is better.
I use sed for non-interactve editing as well. Below is a favourite of script of mine ("ins") that I use frequently for non-interactively inserting text at the top or at any line in text files.
#!/bin/sh
case $# in :)
;;0) exec echo usage: ${0##*/} target \[line-no\]
;;[12]) sed -i -e ${2-1}r/dev/stdin -e1N $1
esac
Stupid examples:
echo 93.184.216.34 example.com|ins /etc/hosts
cat 84*.c|ins 084.l 151 # insert some .c files at line 151