I have this nested bash for loop where the first loop represents the range of servers, and the second loop reads each lines of the .txt file. Then will do a zgrep -i and find for a string on the matching line.
keys.txt is as follow:
1121313232323-1 1121313244234-1 1121867575757-1 Bash Loops:
for i in {1..80}; do for j in `cat keys.txt`; do zgrep -i 'InitialRequest' /var/logs/server$i/* >> /var/log/result.log; done; done & This runs but its logging every instance where 'InitialRequest' is defined. What im looking for is to only log lines where the key line is matched to 'InitialRequest' with their key value.
The result i'm expecting is like this (with Key value from J inner loop 1121313232323-1 and with string 'InitialRequest' plus the remaining of the line:
1121313232323-1 InitialRequest http://someramdomurl.com What I'm getting is like (just the matching string without the Key value from the J inner loop:
InitialRequest http://someramdomurl.com InitialRequest http://someotherramdomurl.com InitialRequest http://someotherotherramdomurl.com Can anyone advise where is my error?
https://stackoverflow.com/questions/66894318/nested-bash-loop-runs-but-logic-is-not-correct April 01, 2021 at 03:42AM
没有评论:
发表评论