I have one text file and I need to get 2 variables from the same text and put them in one command like
for i in `cat TEXT | grep -i UID | awk '{print($2)}'` &&
x in `cat TEXT | grep -i LOGICAL | awk '{print($4)}'`
do
echo "naviseccli -h 10.1.1.37 sancopy -create -incremental -name copy_$i -srcwwn $x -destwwn xxxxxxxxxxxxxxxxxxxxxx -verify -linkbw 2048" >> OUTPUT
done
is there any possible way to accomplish that am storage admin and need to do tons of commands so i need to get this script to do it
You could make use of file descriptors. Moreover, your
cat
,grep
,awk
command could be combined into a singleawk
command:Perform the
cat
operations first and save the result into two arrays. Then you can iterate with an index over one array and use the same index to also access the other one.See http://tldp.org/LDP/abs/html/arrays.html about arrays in bash. Especially see the section "Example 27-5. Loading the contents of a script into an array".
With that resource you should be able to both populate your arrays and then also process them.
Since your words don't have spaces in them (by virtue of the use of
awk
), you could use:This uses Process Substitution to give
paste
two files which it pieces together. Each line will have two fields on it, which are read intoi
andx
for use in the body of the loop.Note that there is no need to use
cat
; you were eligible for a UUOC (Useless Use ofcat
) award.Imma take a wild guess that
UID
andLOGICAL
must be on the same line in your incomingTEXT
, in which case this might actually make some sense and work: