Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash(文本提取)_Bash_Shell_Awk_Sed_Grep - Fatal编程技术网

Bash(文本提取)

Bash(文本提取),bash,shell,awk,sed,grep,Bash,Shell,Awk,Sed,Grep,我在一个文件中有一行很长的信息,我想把它提取出来,这样最终的结果就像这个output.txt?请帮忙 我的输入看起来像: [{"city":"london","first name":"peter","last name":"hansen","age":"40"}, {"city":"new york","first name":"celine","last name":"parker","age":"36"] Output.txt peter (40) celine (36) 如果是正确的

我在一个文件中有一行很长的信息,我想把它提取出来,这样最终的结果就像这个output.txt?请帮忙

我的输入看起来像:

[{"city":"london","first name":"peter","last name":"hansen","age":"40"},
{"city":"new york","first name":"celine","last name":"parker","age":"36"]
Output.txt

peter (40)
celine (36)

如果是正确的json,另一种选择是使用jq:


假设输入字符串存储在文件input.txt中,即

你可以通过

ruby -e "puts $(<input.txt).map {|x| %(#{x[:'first name']} (#{x[:age]}))}"

这使用了一个事实,即输入恰好是一个语法有效的Ruby表达式,表示一个由两个哈希组成的数组。

在右方括号之前不应该有一个右大括号吗?
echo '[{"city":"london","first name":"peter","last name":"hansen","age":"40"},{"city":"new york","first name":"celine","last name":"parker","age":"36"}]' >input.txt
ruby -e "puts $(<input.txt).map {|x| %(#{x[:'first name']} (#{x[:age]}))}"