我正在运行以下命令并获取 4 行作为输出。
userid@server:/home/userid# ps -ef|grep process
这是命令的输出。
userid 10117 9931 0 06:25 pts/0 00:00:00 grep process
userid 15329 1 0 Jul11 ? 00:03:40 process APP1
userid 15334 15329 1 Jul11 ? 2-00:40:53 process1 APP1
userid 15390 15334 0 Jul11 ? 05:19:31 process2 APP1
我想使用 perl 将值 APP1 保存到变量中。所以我想要一个像 $APP = APP1
这样的输出。
最佳答案
试试这个(在这种情况下,您的输出位于文件 in.txt
中):
perl -ne ' /(APP\d+)/g; print "$1\n";' in.txt
打印:
APP1
APP1
APP1
关于linux - 在perl中从数组中获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19929389/