使用awk的输出运行命令 [英] Using output of awk to run command

查看:115
本文介绍了使用awk的输出运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Shell脚本的新手,似乎无法弄清楚这个看似简单的任务.我有一个约250行的文本文件(ciphers.txt),我想将每行的第一列用作命令中的参数.任何帮助将不胜感激!

I am brand new to shell scripting and cannot seem to figure out this seemingly simple task. I have a text file (ciphers.txt) with about 250 lines, and I would like to use the first column of each line as an argument in a command. Any help would be greatly appreciated!

命令是:

openssl s_client -connect host:port -cipher argument

当我一次执行一个命令时,效果很好,但是我真的不想运行相同的命令250次以上.到目前为止,这是我的脚本:

It works fine when I do one at a time but I do not really want to run the same command 250+ times. Here is my script so far:

awk '{command = "openssl s_client -connect localhost:4433 -cipher > results.txt"
print $0 | command}' ciphers.txt

我一直收到错误消息,所以我很确定自己某处存在语法错误. awk的输出是否在-cipher后附加?

I keep getting an error so I am pretty sure I have a syntax error somewhere. Is the output of awk being appended after -cipher?

推荐答案

在awk中使用system:

awk '{ system("openssl s_client -connect host:port -cipher " $1) }' ciphers.txt

这篇关于使用awk的输出运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆