我在完成这个简单的任务时遇到了麻烦:
cat file | grep -E ^[0-9]+$ > file_grep
diff file file_grep
Run Code Online (Sandbox Code Playgroud)
问题是,我想没有这样做 file_grep
我试过了:
diff file `cat file | grep -E ^[0-9]+$`
Run Code Online (Sandbox Code Playgroud)
和
diff file "`cat file | grep -E ^[0-9]+$`"
Run Code Online (Sandbox Code Playgroud)
和其他一些组合:-)但我不能让它工作.我总是得到一个错误,当diff
得到额外的参数,这是过滤的文件的内容grep
.
当我想echo
在这样的脚本中命令输出时(使用反引号转义),类似的东西总是对我有用:
echo `ls`
Run Code Online (Sandbox Code Playgroud)
谢谢
我在Win7机器上安装Python 3.2 32bit,有以下选项:
安装后将.py文件编译为字节代码
我应该选择未选中的选项还是建议编译?
我在ReactJS中做一个简单的事情时收到错误"TypeError:无法读取未定义的属性'setState'.我正在尝试使用axios来填充带有响应数据的输入.到目前为止没有成功.我对axios和ReactJs都很新,所以它可能是我忽略的非常简单的东西?
在修复TypeError之后,我希望"RESPONSE TEXT"显示在表单的输入字段中.
这是我的组成部分:
class BasicInfoBlock extends React.Component {
constructor(props) {
super(props);
this.state = { name : "EventTestName" };
}
componentDidMount() {
axios
.get(getBaseUrl()+`get`)
.then(function (response) {
this.setState({name: "RESPONSE TEXT"});
//this.setState({name: response.data.name});
})
.catch((e) =>
{
console.error(e);
});
//this.setState({});
}
render(){
return(
<form className="form-horizontal">
<div className="form-group">
<label htmlFor="eventName" className="col-sm-2 control-label">Name</label>
<div className="col-sm-10">
<input type="text" id="eventName" className="form-control" placeholder="Event name" defaultValue={this.state.name}/>
</div>
</div>
</form>
);
}
}
Run Code Online (Sandbox Code Playgroud)
}
谢谢您的帮助
编辑:这不是一个重复的问题,这个问题涉及'this'在回调中不可用.选为重复的问题与bind有关.
我试图使用sed从变量中删除子字符串,如下所示:
PRINT_THIS="`echo "$fullpath" | sed 's/${rootpath}//' -`"
Run Code Online (Sandbox Code Playgroud)
哪里
fullpath="/media/some path/dir/helloworld/src"
rootpath=/media/some path/dir
Run Code Online (Sandbox Code Playgroud)
我想像这样回应其余的完整路径(我在整堆目录中使用它,所以我需要将它存储在变量中并自动执行
echo "helloworld/src"
Run Code Online (Sandbox Code Playgroud)
使用变量就可以了
echo "Directory: $PRINT_THIS"
Run Code Online (Sandbox Code Playgroud)
问题是,我无法获取sed删除子字符串,我做错了什么?谢谢
在我在项目中使用的源文件中,有一个ssize_t
和size_t
变量之间的比较:
ssize_t sst;
size_t st;
if(sst == st){...}
Run Code Online (Sandbox Code Playgroud)
我想摆脱警告:
warning: comparison between signed and unsigned integer expressions
Run Code Online (Sandbox Code Playgroud)
但我不确定,我应该向另一个转变哪个变量?
if((size_t)sst == st){...}
Run Code Online (Sandbox Code Playgroud)
要么
if(sst == (ssize_t)st){...}
Run Code Online (Sandbox Code Playgroud)
什么是更安全,更好,更清洁?谢谢
当我在myFile中达到EOF时,Seekg似乎不起作用.
ifstream myFile("/path/file");
for(int i; i < 10; i++){
myFile.seekg(0);//reset position in myFile
while(getline(myFile, line)){
doSomething
}
}
Run Code Online (Sandbox Code Playgroud)
所以,现在我在每个循环打开输入流:
for(int i; i < 10; i++){
ifstream myFile("/path/file");//reset position in myFile
while(getline(myFile, line)){
doSomething
}
}
Run Code Online (Sandbox Code Playgroud)
但我宁愿寻求位置0.我怎样才能实现这一目标?
在 Linux 上,我使用这些标志来使用 gcc 进行编译
CFLAGS=-Wall -pedantic -g -Wextra -pthread
Run Code Online (Sandbox Code Playgroud)
我在 VS 中可以选择哪些选项来启用类似的标志?额外警告等
我需要像这样调用我的程序:
./program hello -r foo bar
Run Code Online (Sandbox Code Playgroud)
我从argv [1]中打招呼,但我在价值栏上遇到麻烦,我还应该将"r:"更改为其他内容吗?
while((c = getopt(argc, argv, "r:")) != -1){
switch(i){
...
case 'r':
var_foo = optarg;
//shell like argument shift here?
var_bar = optarg;
break;
...}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过argv来做到这一点,但有没有办法用getopt与bash类似的方式来做到这一点?
谢谢.
我想从这里使用正则表达式:
https://tools.ietf.org/html/rfc3986#appendix-B
我试图像这样编译它:
#include <regex.h>
...
regex_t regexp;
if((regcomp(®exp, "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", REG_EXTENDED)) != 0){
return SOME_ERROR:
}
Run Code Online (Sandbox Code Playgroud)
但是我坚持使用regcomp的返回值:
REG_BADRPT
Run Code Online (Sandbox Code Playgroud)
根据男人的意思是:
使用重复运算符无效,例如使用*
第一个字符.
这个男人有类似的意思:
?
,*
或者+
没有有效的正则表达式
我使用自己的正则表达式编写了解析器,但我也想测试这个,因为它正式在rfc中.我不打算用它进行验证.
我想实现两件事.
首先,我希望此连接不区分大小写.
我过去曾使用过这种不敏感的where子句
where b.foo.Equals(foo, StringComparison.OrdinalIgnoreCase)
Run Code Online (Sandbox Code Playgroud)
但我现在不知道如何在加入中使用它.
其次,我想返回带有作者姓名和书籍数量的元组.
var query = from b in Books
join a in authors on b.Author equals a
select Tuple.Create(a, _count_of_authors_books_);
return query;
Run Code Online (Sandbox Code Playgroud)
谢谢.