没有序言,
$ cat in.txt a b c d $ sed '=;N' in.txt 1 a b 3 c d
看起来'N'命令适用于其他每一行.也许这很自然,因为命令'N'加入下一行并改变当前行号.但,
$ sed 'N;$!P;$!D;$d' thegeekstuff.txt
(我在这里看到这个)
上面的例子删除了文件的最后两行.这不仅适用于偶数行编号的文件,也适用于奇数行编号的文件.因此,在此示例中,'N'命令在每一行上运行.
有什么区别?
你能不能告诉我为什么当我像这样运行sed时我看不到最后一行?
# sed N odd-lined-file.txt
我的二进制文件看起来像这样.
00000000: 0000 0803 0000 ea60 0000 001c 0000 001c
00000010: 0000 0000 0000 0000 0000 0000 0000 0000
Run Code Online (Sandbox Code Playgroud)
左栏是地址.
我只是尝试阅读0000 0803(= 2051)如下
ifstream if;
if.open("file");
uint32_t a;
if >> a;
Run Code Online (Sandbox Code Playgroud)
正如预期的那样......它不起作用:-(
a执行后只是0.
我试过long, int, unsigned int, unsigned long.都失败了.
为什么这些不起作用,我怎样才能实现目标?
我正在使用jni开发Android应用程序.
我使用GetStringUTFChars函数如下
jboolean iscopy;
const char* trainfile = (env)->GetStringUTFChars(jstr, &iscopy);
Run Code Online (Sandbox Code Playgroud)
但我看到了另一个这样的例子
const char *inCStr = (*env)->GetStringUTFChars(env, inJNIStr, NULL);
Run Code Online (Sandbox Code Playgroud)
两者都运作良好.但我找不到任何关于前语法的文档,即使是更简洁.
我在哪里可以找到文档,它们之间有什么区别吗?
看看这个小片段.
y<v|!v?:y=v;
Run Code Online (Sandbox Code Playgroud)
(y是最小值,v是当前比较值.这种方式会让你更容易思考.)
这个片段的含义很简单.
如果当前值v小于最小值y,则设置新的最小值(y=v).但v=0案件被排除在外.
然后我想如果可以生成'不良代码',结果应该是相同的.我的意思是,
y>v&v?y=v:;
Run Code Online (Sandbox Code Playgroud)
这段代码应该做同样的事情.但它无法编译.错误如下.
error: expected expression
for(int v: a) v=abs(a[i]-v), x>v?:x=v, y>v&v?y=v:;
^
Run Code Online (Sandbox Code Playgroud)
有点奇怪.我认为两个代码是相同的.如果后三元运算符是错误的,那么前者应该有同样的问题.但事实并非如此.
有人可以解释原因吗?
下一个问题.我插入一个0编译.y>v&v?y=v:0;
然后我得到了一个错误的答案.所以我改变了&对&&.y>v&&v?y=v:0;
最后我得到了一个正确的答案.但是没有这些过程,使用|运营商可以做到全部.为什么?
<附加信息>
我的编译器版本如下.
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.4.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)
并编译选项:
g++ -std=c++11 my.cpp
Run Code Online (Sandbox Code Playgroud)
如果您想要测试示例代码,这将有所帮助.
#include <iostream>
#include <vector>
using namespace std; …Run Code Online (Sandbox Code Playgroud) c++ ternary-operator bitwise-operators logical-operators logical-or
我是红宝石的新手.
当我使用irb时,会发生一些事情.(没有打印)
有人对此有任何建议吗?
我甚至不知道什么搜索关键字对于这种情况是可以的.
(也许是特定于环境的问题?你怎么看?)
irb(main):010:0> a = [3,2,1]
=> [3, 2, 1]
irb(main):011:0> a.each
=> #<Enumerable::Enumerator:0x7f413a20d668>
irb(main):012:0> a.each{|x| print x}
321=> [3, 2, 1]
irb(main):013:0> a.each do |x| print x end
321=> [3, 2, 1]
irb(main):014:0> 1.to 9
NoMethodError: undefined method `to' for 1:Fixnum
from (irb):14
from :0
irb(main):015:0> 1.to(9) do |x| print x done
irb(main):016:1> 1.to(9) { |x| print x }
irb(main):017:1> 1.to(9)
irb(main):018:1> 1.upto(9)
irb(main):019:1> 1.upto(9) do |x| print x done
irb(main):020:2> 1.upto(9) { |x| print x …Run Code Online (Sandbox Code Playgroud) 我的文字如下.
cat
dog
elephant
cat (1)
zebra(1)
snow leopard
shark (other)
animal (hi) (2)
Run Code Online (Sandbox Code Playgroud)
我想按如下方式更换它们.
[[cat]]
[[dog]]
[[elephant]]
[[cat]] (1)
[[zebra]](1)
[[snow leopard]]
[[shark]] (other)
[[animal (hi)]] (2)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢你提前.
注意cat (1)和zebra(1)(行4~5)之间的区别,空格.
我在chef属性文件中看到了这段代码.
include_recipe "deployment"
include_attribute "postgresql"
include_attribute "redis"
include_attributes "uaa"
include_attributes "service_lifecycle"
Run Code Online (Sandbox Code Playgroud)
有什么不同?include_attribute与include_attribute*S*
我找不到任何关于include_attribute*S*的文档
$ OPTION="-n" $ echo $OPTION $
什么都没发生.我期待这个.
$ OPTION="-n" $ echo $OPTION -n $
为什么是这样?
我错误输入|(bar)为\(反斜杠)
locate abcdef \ grep 2
Run Code Online (Sandbox Code Playgroud)
像这样.然后bash开始查找名称中包含"2"的所有文件.
为什么会这样?
我有一个名字的文件-q(看起来这是偶然的)
我想看看它的内容,所以我尝试了这些
$ cat '-q'
$ cat "-q"
$ cat $'-q'
Run Code Online (Sandbox Code Playgroud)
但没有任何效果.(所有给出相同的错误cat: invalid option -- 'q')
有没有办法看到它的内容?
那些看起来一样.也许我对<操作员的误解.
为什么这两个命令给出相同的结果?