Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using output of awk to run command

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!

the command is:

openssl s_client -connect host:port -cipher argument 

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 

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?

like image 451
nLee Avatar asked Dec 05 '13 01:12

nLee


People also ask

How do I run a command in awk?

Call External Command From awkawk + cp: Read input of a file list, and copy the files to a required destination with a defined name pattern. awk + md5sum: Read input containing a list of filenames, output the filename and the MD5 hash of the file.

What is the output of the command awk?

awk '{print $1}' information. txt prints the first column. Then the output of that command (which you saw earlier on) is piped, using the pipe symbol | , to the head command, where its -1 argument selects the first line of the column.

How do I run awk command specified in a file?

In order to tell awk to use that file for its program, you type: awk -f source-file input-file1 input-file2 … The -f instructs the awk utility to get the awk program from the file source-file (see Command-Line Options). Any filename can be used for source-file .

How do you save output from awk to variable?

`awk` command uses '-v' option to define the variable. In this example, the myvar variable is defined in the `awk` command to store the value, “AWK variable” that is printed later. Run the following command from the terminal to check the output.


1 Answers

Use system from within awk:

awk '{ system("openssl s_client -connect host:port -cipher " $1) }' ciphers.txt 
like image 185
David Avatar answered Oct 04 '22 06:10

David