如何反转grep命令的输出?

Анд*_* Ка 3 linux bash shell grep

我对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)

什么都没有...。也许存在更好的解决方案?

Nah*_*eul 5

grep只是过滤器man grepprint lines matching a pattern,来更改顺序,因此必须使用其他工具,因为只有两项可能会添加|sort|sort -r(按反向排序)可以提供帮助。

grep -E '"ServiceUserName"|"ServicePassword"' | sort -r >> user.txt
Run Code Online (Sandbox Code Playgroud)