Bik*_*Bik 3 string bash grep expression sed
假设我有一个字符串:
random text before authentication_token = 'pYWastSemJrMqwJycZPZ', gravatar_hash = 'd74a97f
Run Code Online (Sandbox Code Playgroud)
我想要一个 shell 命令来提取下一个 之前"authentication_token = '"和之前的所有内容'。
所以基本上,我想回来pYWastSemJrMqwJycZPZ。
我该怎么做呢?
使用参数扩展:
#!/bin/bash
text="random text before authentication_token = 'pYWastSemJrMqwJycZPZ', gravatar_hash = 'd74a97f"
token=${text##* authentication_token = \'} # Remove the left part.
token=${token%%\'*} # Remove the right part.
echo "$token"
Run Code Online (Sandbox Code Playgroud)
请注意,即使随机文本包含authentication token = '...'.
| 归档时间: |
|
| 查看次数: |
6840 次 |
| 最近记录: |