来自地图对象的grep string
我正在尝试在客户端对象中提取每个用户名值并存储在数组(bash)中。 都无法匹配吗
//a.txt
username = "fakeuservalue"
clients = [
{
username = "user1"
},
{
username = "user2"
}
]
x=$(cat a.txt | grep -e 'username\s+=\s+\"(.*)\"')
echo $x
但是,GREP即使在Regex101.com中匹配的任何线索 ?我还尝试在“客户端”对象上添加另一个检查检查,以便跳过检索“ FakeUservalue”。
I'm trying to extract each username value in clients object and store in array (bash). However, grep failed to match even through matched in regex101.com
//a.txt
username = "fakeuservalue"
clients = [
{
username = "user1"
},
{
username = "user2"
}
]
x=$(cat a.txt | grep -e 'username\s+=\s+\"(.*)\"')
echo $x
Any clues? I'm also try to add another check on "clients" object so that skip retrieve "fakeuservalue".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
在线演示:
输出:
You can use
See the online demo:
Output:
1。使用
GREP
2。提取用户名值2。将用户名值分配到数组
arr1
。3。打印所有数组
arr1
elements4。在数组中打印第一个和最后一个元素
arr1
具有3个元素1. Extract username values using
grep
2. Assign username values into array
arr1
.3. Print all array
arr1
elements4. Print first and last elements in array
arr1
having 3 elements