I want to add a line to a text file so that the result is sorted where the text file was originally sorted. For instance:
cp file tmp; echo "new line" >> tmp; sort tmp > file; rm -f tmp
I would REALLY want to do this without a temporary file and without semicolons (use pipes instead?); use sedwould be acceptable. Is this possible, and if so, how?
sed
echo "New Line" | sort -o file - file
-o file ( ). - " ", . file ' file'. Unix- ( ) 7- UNIX ™ 1978 , , . .
-o file
-
file
, "", , , , , :
echo "New Line" | sort -o file -m - file
.
, - :
$ echo "something" >> file; sort file -o file
, , comm ( ), , ( ).
comm
: comm -3 file <(echo "new line") |tr -d '\t'
comm -3 file <(echo "new line") |tr -d '\t'
"": sort -m file <(echo "new line")
sort -m file <(echo "new line")
, , , , (, awk perl).
?
: , :
val=$(cat file); { echo "$val"; echo "new line"; } | sort > file
/:
SQLite .
B-tree - , SQLite ...
, : , , , : https://unix.stackexchange.com/questions/87772/add-lines-to-the-beginning-and-end-of-the-huge-file
sgrep : https://askubuntu.com/questions/423886/efficiently-search-sorted-file/701237#701237
sgrep