FILE:
hello
world
I would like to use a scripting language (BASH) to execute a command that reads each WORD
in the FILE
above and then plugs it into a command
.
It then loops to the next word in the list (each word on new line).
It stops when it reaches the end of the FILE
.
Progression would be similar to this:
Read first WORD
from FILE
above
Plug word into command
command WORD > WORD
Repeat this process, but with next to nth WORD
(each on a new line).
Terminate process upon reaching the end of FILE
above.
Result of BASH command on FILE
above:
hello:
RESULT OF COMMAND UPON WORD hello
world:
RESULT OF COMMAND UPON WORD world
Syntax: Read file line by line on a Bash Unix & Linux shell file. The -r option passed to read command prevents backslash escapes from being interpreted. Add IFS= option before read command to prevent leading/trailing whitespace from being trimmed. while IFS= read -r line; do COMMAND_on $line; done < input.
If "name=foo" is always in the same position in the line you could simply use: awk '{print($3)}' , that will extract the third word in your line which is name=foo in your case. He told "also other parameters may or may not be there" hence you may not use a positional logic.
You can use the "for" loop to do this. something like..
for WORD in `cat FILE`
do
echo $WORD
command $WORD > $WORD
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With