我正在编写一个脚本,用于检查连接到服务器的所有用户的列表(使用 who),并将仅包含字母 a、b、c 或 d 的用户名列表写入文件信息。这是我到目前为止所拥有的:
who | grep '[a-d]' >> Information
Run Code Online (Sandbox Code Playgroud)
但是,显示此内容的命令:
username pts/148 2019-01-29 16:09 (IP address)
Run Code Online (Sandbox Code Playgroud)
我不明白的是为什么我的 grep 搜索还显示 pts/148、日期、时间和 IP 地址。我只是希望它将用户名发送到文件信息。
任何帮助表示赞赏。
小智 5
另一种方法是使用该命令 cut仅获取字符串的第一部分。
who | cut -f 1 -d ' ' | grep '[a-d]' >> Information
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5484 次 |
| 最近记录: |