协议缓冲区与平坦缓冲区(Protocol Buffers vs Flat Buffers [closed])
所以,我目前正在研究Protocol Buffers广泛使用的项目,主要是为了将复杂对象存储在键值数据库中。
迁移到Flat Buffers是否会在性能方面提供相当大的好处?
更一般地说,是否有充分的理由使用Protocol Buffers而不是Flat Buffers?
So, I'm currently working on a project where Protocol Buffers is used extensively, mainly as a way to store complex objects in a key-value database.
Would a migration to Flat Buffers provide a considerable benefit in terms of performance?
More in general, is there ever a good reason to use Protocol Buffers instead of Flat Buffers?
原文:https://stackoverflow.com/questions/43054786
最满意答案
您想使用“先前在脚本中定义的变量”。 以下是变量:
file="path/to/input/file" var="ssh_param" msg="#New path defined" new="/etc/ssh/file"
以下是使用这些变量的命令:
lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//') if [ "$lineno" ] then sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file" else sed -i -r "$ s|$|\n$msg\n$var $new|" "$file" fi
笔记:
从您的示例中可以看出,变量名称可能在脚本中多次出现,但只有最后一个名称未被注释。 我们在这里使用它来简化代码。 脚本中变量最后一次出现的行号可从以下位置找到:
lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//')
grep -n
部分查找出现变量名的行号列表。tail -n1
只返回最后一行。sed
命令从输出中删除除行号以外的所有行号。替换是通过以下命令完成的:
sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file"`
这使用sed的能力来操作特定的行号。 该行由三行代替:第一行是现有行的副本,但是已注释,第二行是消息,第三行是变量的新定义。
如果变量当前不在文件中,则
lineno
为空。 在这种情况下,我们希望将新行添加到文件的末尾。 这是通过类似但更简单的sed
命令完成的:sed -i -r "$ s|$|\n$msg\n$var $new|" "$file"
第一个
$
告诉sed
仅在最后一行操作。 第二个$
出现在substitute命令中,表示该行的结束。 您的消息和新变量定义将被追加。例
以此为输入:
#ssh_param dasfda ssh_param /path/to/file
上面的代码用以下代码替换文件:
#ssh_param dasfda #ssh_param /path/to/file #New path defined ssh_param /etc/ssh/file
(如果你想要空行来分隔,只需在
sed
输出表达式中添加一些\n
。)You wanted to use "variables defined earlier in the script." Here are the variables:
file="path/to/input/file" var="ssh_param" msg="#New path defined" new="/etc/ssh/file"
Here are the commands which use those variables:
lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//') if [ "$lineno" ] then sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file" else sed -i -r "$ s|$|\n$msg\n$var $new|" "$file" fi
Notes:
It appears from your examples that the variable name may occur multiple times in the script but only the last one is uncommented. We use that here to simplify the code. The line number of the last appearance of the variable in the script is found from:
lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//')
The
grep -n
part finds a list of line numbers on which the variable name occurs.tail -n1
returns only the last such line. Thesed
command removes all but the line number from the output.The substitution is done by this command:
sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var $new|" "$file"`
This uses sed's ability to operate on a particular line number. That line is substituted by three lines: the first is a copy of the existing line but commented, the second is the message, and the third is the new definition of the variable.
If the variable is not currently in the file, then
lineno
is empty. In this case, we want to add the new lines to the end of the file. This is done via a similar but simplersed
command:sed -i -r "$ s|$|\n$msg\n$var $new|" "$file"
The first
$
tellssed
to operate only on the last line. The second$
appears in the substitute command where it signifies the end of that line. Your message and new variable definition are appended.Example
With this as the input:
#ssh_param dasfda ssh_param /path/to/file
The above code replaces the file with:
#ssh_param dasfda #ssh_param /path/to/file #New path defined ssh_param /etc/ssh/file
(If you want blank lines to space things out, just add some
\n
to thesed
output expression.)
相关问答
更多-
LINUX 如何查看JPG文件[2022-06-13]
find -
这是使用sed的更简单的版本: #!/usr/bin/sed -f s/^\(pm.max_children = \).*/\15/ s/^\(pm.start_servers = \).*/\11/ s/^\(pm.min_spare_servers = \).*/\11/ s/^\(pm.max_spare_servers = \).*/\13/ s/^\(pm.max_requests = \).*/\12000/ 你能把它放在一个单独的文件中并从你的脚本中调用吗? 我同意Kerrek SB的意见 ...
-
您想使用“先前在脚本中定义的变量”。 以下是变量: file="path/to/input/file" var="ssh_param" msg="#New path defined" new="/etc/ssh/file" 以下是使用这些变量的命令: lineno=$(grep -n "$var" "$file" | tail -n1 | sed 's/:.*//') if [ "$lineno" ] then sed -i -r "$lineno s|#?(.*)|#\1\n$msg\n$var ...
-
好的,我建议创建一个关系文本文件,你可以解析,以防你认为关系可以在以后改变,或者只是为了让你的代码更容易阅读和变化。 然后可以对其进行解析以找到原料和配合物之间所需的关系。 让它成为“relations.txt”,类型为: omelette: 5 x eggs + 1 x onions pileofomelettes: 6 x omelette 在这里,您可以放置任意数量的成分类型: 复杂:number1 x ingredient1 + number2 x ingredient2 + ... 等等。 而你 ...
-
您可以使用此find命令: find . -type f -exec bash -c '[[ $(wc -l < "$1") -gt 2 ]] && echo "$1"' _ '{}' \; You can use this find command: find . -type f -exec bash -c '[[ $(wc -l < "$1") -gt 2 ]] && echo "$1"' _ '{}' \;
-
未经测试 for file in *; do in_pgp_section=false pgp_text="" while read line; do if [[ $line == "-----BEGIN PGP MESSAGE-----" ]]; then in_pgp_section=true fi if ! $in_pgp_section; then echo "$line" ...
-
这是sed的工作! 来自GNU sed主页: Sed通常用于使用模式匹配来提取文件的一部分或者在文件中替换多次出现的字符串。 这是你如何做到的: sed '/^Filename:/s!\(./debs/\)\(.*\).deb!\1download.php?p=\2!' /path/to/input > /path/to/output 哪里: /^Filename:/查找以( ^ )文本'Filename:'开头的行 s!search!replace! 将'search'替换为'replace',其中's ...
-
$ sed '/^AppName: */{h;s///;x;}; /^\(AppName_.._..:\).*/{s//\1/;G;s/\n/ /;}' MenuSettings.txt AppName: "http://www.bbc.co.uk” DoubleWidthTile: "False" TileColor: "0.76 0 0.24 1" AnimationSize: "10 10" AppName_xx_XX: "http://www.bbc.co.uk” AppName_yy_YY: "h ...
-
即使这个问题应该已经在这个线程中得到了解答,但我并没有设法使“一行一行”解决方案有效。 这个命令: perl -pe 's/START.*STOP/replace_string/g' file_to_change 似乎不适合我,并且不执行多行替换。 我不得不将它分成两个不同的Perl脚本,如下所示: perl -pe 's/bbb\tbbb\n.*/placeholderstring/g' foo1.txt | perl -pe 's/placeholderstring ccc\tccc/eee\tee ...
-
sed将不允许在替换文本中使用多个未转义的换行符。 你可以使用awk: awk -v toedit="$toedit" '/
/{print toedit; next} 1' file http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is dist ...