我gitbash在Windows中。我正在尝试运行,jq但它给了我错误。
$ ./jq-win64.exe
jq
parse error: Invalid numeric literal at line 2, column 0
Run Code Online (Sandbox Code Playgroud)
目的:我想jq用来解析json。
我想在脚本执行之前找出 Mac OS X 机器上的默认浏览器是否是 Google Chrome。
我该怎么做?谢谢!
foo='abc'
bar='xyz'
var=bar
Run Code Online (Sandbox Code Playgroud)
我什么'xyz'时候可以访问var?
我试过了:
$(echo $var)
Run Code Online (Sandbox Code Playgroud)
和
$(eval echo $var)
Run Code Online (Sandbox Code Playgroud)
我得到了 bar: command not found
我正在尝试NSArray从NSAppleEventDescriptor. 几年前有人问过一个类似的问题,尽管解决方案返回一个NSString.
NSString *src = [NSString stringWithFormat: @"return {\"foo\", \"bar\", \"baz\"}\n"];
NSAppleScript *exe = [[NSAppleScript alloc] initWithSource:src];
NSAppleEventDescriptor *desc = [exe executeAndReturnError:nil];
NSLog(@"%@", desc);
// <NSAppleEventDescriptor: [ 'utxt'("foo"), 'utxt'("bar"), 'utxt'("baz") ]>
Run Code Online (Sandbox Code Playgroud)
我不确定我需要什么描述符函数来将值解析为数组。
考虑tuple使用内置方法的基本内容str.startswith():
>>> t = 'x','y','z'
>>> s = 'x marks the spot'
>>> s.startswith( t )
True
Run Code Online (Sandbox Code Playgroud)
当使用元组时,似乎需要一个循环str.strip():
>>> for i in t: s.strip(i)
...
' marks the spot'
'x marks the spot'
'x marks the spot'
Run Code Online (Sandbox Code Playgroud)
这或许似乎很浪费; 是否有更有效的方法来使用元组项目str.strip()?s.strip(t)似乎合乎逻辑,但是,没有bueno.
我正在尝试在Objective-C中执行简单的AppleScript.代码是:
NSString *emailString = @"tell application \"Mail\" to activate";
NSAppleScript *emailScript = [[NSAppleScript alloc] initWithSource: emailString];
NSDictionary *errorDict = NULL;
[emailScript executeAndReturnError: &errorDict];
Run Code Online (Sandbox Code Playgroud)
并得到了这个恼人的错误:
NSAppleScriptErrorMessage:Mail出错:应用程序未运行.NSAppleScriptErrorRange:NSRange:{27,8} NSAppleScriptErrorBriefMessage:应用程序未运行.NSAppleScriptErrorNumber:-600 NSAppleScriptErrorAppName:Mail
如果我从脚本编辑器执行脚本,这没问题.我需要一些帮助 - 谢谢!
我正在使用jq将嵌套.json文件转换为.csv,但是,当我在JSON 中有特定的键,值时似乎存在问题。我使用的脚本来自这个答案,如果我从输入文件中删除一行,它就可以工作。
错误:
jq: error (at example.json:0): object ({"favicon":...) is not valid in a csv row
Run Code Online (Sandbox Code Playgroud)
错误消息不是很具有描述性,因为它提到的对象似乎不是罪魁祸首。
json2csv.jq
paths as $path
| {path: $path, value: getpath($path)}
| select(.value|type == "object" )
| select( [.value[]][0] | type != "object")
| .path + ([.value[]])
| @csv
Run Code Online (Sandbox Code Playgroud)
example.json(通过https://jsonlint.com验证):
{
"items": [
{
"id": 1234,
"title": "Title of Item",
"internet": {
"favicon": "https://example.com/icon.png",
"domain": "https://example.com"
}, …Run Code Online (Sandbox Code Playgroud) 我试图找到"笑的话"或类似的,例如hahaha,hihihi,hueheu内用户的邮件.我目前的做法如下:
>>> substring_list = ['ha', 'ah', 'he', 'eh', 'hi', 'ih', 'ho', 'hu', 'hue']
>>> pattern_core = '|'.join(substring_list)
>>> self.regex_pattern = re.compile(r'\b[a-z]*(' + pattern_core + r'){2,}[a-z]*\b', re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)
在[a-z]*允许一些余地,当谈到错别字(例如ahhahah).原则上,这种方法运作得相当好.问题是需要维护它需要substring_list更新以匹配新形式的"笑声词"(例如,添加xi); "笑声"似乎在各国之间变得非常明显.
现在我想知道我是否可以在不知道单独模式的情况下以某种方式找到基于重复模式(大小,例如2-4)的单词.例如,hurrhurr包含hurr重复模式.在理想情况下,我可以(a)匹配hurrhurr和(b)识别核心模式hurr.我不知道这是否可以使用正则表达式.
在Linux Vm中,我试图更改50+文件的第二行.
我已成功使用下面的命令,用于没有符号的字符串.
perl -p -i -e 's/.*/new_line / if $.==2' .
Run Code Online (Sandbox Code Playgroud)
但是现在我尝试使用此命令添加新字符串"#$ new_line $":
perl -p -i -e 's/.*/# $Header$ / if $.==2' .
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
Final $ should be \$ or $name at -e line 1, within string
syntax error at -e line 1, near "s/.*/# $Header$ /"
Execution of -e aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.先感谢您.
我有以下文件夹结构:
/a/b/c/d/e.txt
/a/b/c/e.txt
/a/b/m.txt
Run Code Online (Sandbox Code Playgroud)
我想要输出
/a/b/c/d/e.txt
/a/b/m.txt
Run Code Online (Sandbox Code Playgroud)
e.txt的任何路径都可以.到目前为止,我能够过滤掉唯一的文件,但是我正在失去完整路径的价值.
find . -name '*.txt' | awk -F "/" '{print $NF}' | uniq
Run Code Online (Sandbox Code Playgroud)
输出是
e.txt
f.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法使用awk,sed或任何其他命令打印上述场景中的完整路径?