linux - 想从 httpconf 文件中找到端口号并通过 echo 命令显示它 .cat httpd.conf | grep -oE "Listen' [0-9]{1,4 }'"

标签 linux shell unix

想从httpconf中查找端口号文件并通过 echo 命令显示它,这就是我的想法,但需要进一步编辑:

cat httpd.conf | grep -oE "Listen'[0-9]{1,4}'" > echo "The port number for http is $arg{2}"

需要搜索Listen 80这一行或 Listen <nmbr>并获取该数字以通过 echo 命令显示。
有人可以帮忙吗。

最佳答案

为什么需要 cat?尝试这样的事情:

grep -i 'listen [0-9]' httpd.conf | awk '{print $2}'

使用示例文件 httpd.conf 进行测试:

test test test
Listen 80 xyz
test test test

输出:

80

关于linux - 想从 httpconf 文件中找到端口号并通过 echo 命令显示它 .cat httpd.conf | grep -oE "Listen' [0-9]{1,4 }'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48498167/

相关文章:

linux - 无法使用 visualvm 和相同的 tempdir 分析本地 tomcat

linux - 用一个较短的交换 unix 编译器标志

linux - 当父脚本以交互方式/通过终端调用时,bash 子脚本与父脚本一起退出,但在非交互方式/通过 cron 调用时则不会

c - 编写我自己的基本 shell : Dealing with double quoted arguments

linux - 在linux中从文件名中删除根目录

linux - 独特的列并获得 linux 中的频率

objective-c - 无法使用 GNUstep 在 Objective-C 上构建程序

shell - 在unix系统中合并两个命令的输出

python - ": No such file or directory"

linux - 使用 "sed"显示 test.txt 的前 2 行和后 3 行