Content of the log file is as below,
I, [2018-03-07T10:21:26.315447 #7531] INFO -- : POST http://127.0.0.1:8080/api/v3/internal/allowed 6.69490
I, [2018-03-07T10:21:26.315799 #7531] INFO -- : gitlab-shell: executing git command <git-upload-pack /var/opt/gitlab/git-data/repositories/GitLab-write-logs/write-logs.git> for user with key key-1.
I, [2018-03-07T10:23:00.567841 #7739] INFO -- : POST http://127.0.0.1:8080/api/v3/internal/allowed 5.55714
I, [2018-03-07T10:23:00.568227 #7739] INFO -- : gitlab-shell: executing git command <git-upload-pack /var/opt/gitlab/git-data/repositories/GitLab-read-logs/read-logs.git> for user with key key-3.
I, [2018-03-07T10:23:49.932948 #7851] INFO -- : gitlab-shell: executing git command <git-receive-pack /var/opt/gitlab/git-data/repositories/GitLab-RW-logs/RW-logs.git> for user with key key-5.
I, [2018-03-07T10:55:29.533385 #4778] INFO -- : gitlab-shell: executing git command <git-receive-pack /var/opt/gitlab/git-data/repositories/GitLab-write-logs/write-logs.git> for user with key key-1.
I, [2018-03-07T10:55:29.810478 #4790] INFO -- : POST http://127.0.0.1:8080/api/v3/internal/allowed 0.10971
Pattern = < git-upload-
There are muliple lines with this matching pattern. How can I extract information from each line.
For a example, in the second line we have matching pattern < git-upload- then I would like to extract string '/var/opt/gitlab/git-data/repositories/GitLab-write-logs/write-logs from that line and assign to a variable and do some action.
I would like this process to be done to all matched lines sequentially without repeating the same lines, How should I do that? I appreciate everyone's input
Suppose, we have 50 lines with matching patterns lines in them. Can we grep one line one time do action and pick up next line and repeat the same.
logic:
if more somefile.log | grep -Eq < git-upload-pack ; then
variable = /var/opt/gitlab/git-data/repositories/GitLab-write-logs/write-logs [ .git shouldn't be there]
do some action
fi
should I put while loop (i=0, i++)to repeat the process on each lines like ..check the line if pattern there then execute "if" condition and exit the condition and repeat for next line I am new to scripting and struggling to connect the dots
Thank you all