grep -i 和-o
时间: 2024-06-01 20:09:09 浏览: 51
grep是一个在Unix和类Unix操作系统中用于搜索文本的命令。其中:
- `grep -i`:表示不区分大小写地搜索文本。例如,`grep -i hello.txt`可以匹配到"Hello"或"hello"。
- `grep -o`:表示只输出匹配到的文本部分,而不是整行文本。例如,`grep -o hello file.txt`只会输出文件中所有匹配到的"hello",而不是包含"hello"的整行文本。
相关问题
grep -n 'o\{2\}'test.txt
As an AI language model, I cannot execute commands on your local machine. However, I can explain the syntax and usage of the command you have provided.
The command "grep" is used to search for a specific pattern or keyword in a file or files. The "-n" option is used to display the line number where the pattern or keyword is found. In this case, the pattern being searched for is "o" repeated twice using the curly braces notation "{2}", followed by the name of the file "test.txt".
So, the command will search for all occurrences of the pattern "oo" in the file "test.txt" and display the line numbers where they are found.
ansible -m shell -a "ps aux | grep tfzc_ " all| grep "tfzc_iot" -o -i 同时显示主机IP地址
您可以使用以下命令来同时显示主机IP地址:
ansible all -m shell -a "ps aux | grep tfzc_ | grep tfzc_iot" -o -i | awk '{print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64, $65, $66, $67, $68, $69, $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, $80, $81, $82, $83, $84, $85, $86, $87, $88, $89, $90, $91, $92, $93, $94, $95, $96, $97, $98, $99, $100, $101 {print $2, $1}"
其中,-o 参数指定以人类可读的格式输出结果,-i 参数指定 inventory 文件的路径,也可以使用 -i hosts 来指定 inventory 文件名为 hosts。最后使用 awk 命令将输出中的主机名与 IP 地址互换顺序。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)