Issue
I am trying to write shell script to find Approved user in Jenkins Pipeline log file. I put here a part of pipeline script. how to pick 'MPPortal Administrator' or any user name following by 'Approved by' words? I am new to shell scripting and I have no idea to do it.
Timeout set to expire in 1 hr 30 min
[Pipeline] {
[Pipeline] input
APPROVE?
Proceed or Abort
Approved by MPPortal Administrator
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Library Policy Evaluation)
[Pipeline]
What I tried
grep Approved pipeline.log
then output was
Approved by MPPortal Administrator
expected Output:
MPPortal Administrator
Solution
Using sed
$ sed -n 's/^Approved[^[:upper:]]*\(.*\)/\1/p' input_file
MPPortal Administrator
Using awk
$ awk '$1=="Approved" {print $3,$4}' input_file
MPPortal Administrator
Using grep
and cut
$ grep '^Approved by' input_file | cut -d' ' -f3-4
MPPortal Administrator
Answered By - HatLess Answer Checked By - Clifford M. (WPSolving Volunteer)