如果在给定字符向量中的任何位置找到模式grep,R中是否有一个函数返回?TRUEFALSE
我看到的所有函数都返回了找到的每个元素的当前位置的向量.
我对grep命令有一个问题。在我的脚本中,我使用:
"ServicePassword":fooooooooooo
"ServiceUserName":barrrrrrrrr
grep -E '"ServiceUserName"|"ServicePassword"' >> user.txt
Run Code Online (Sandbox Code Playgroud)
但是在user.txt文件中,我将首先获取“ ServicePassword”:fooooooooooo,然后获取“ ServiceUserName”:barrrrrrrrr我如何使用grep命令将其反向以获取user.txt文件中的第一个ServiceUserName然后ServicePassword输出?我只需要这个顺序。我尝试更改:
grep -E '""ServicePassword""|"ServiceUserName"' >> user.txt
Run Code Online (Sandbox Code Playgroud)
什么都没有...。也许存在更好的解决方案?