dlesny
June 12, 2018, 10:38am
1
Hello
I am trying to write sed code where it will look through the text for lines with specific expression "Started by user" and when found, will also add the following line, and also lines with another expression "Finished:"
sed -n '/Started by user/, +1p, /Finished:/' "${OUTPUT_DIR}/all_job_output" > ${OUTPUT_DIR}/all_job_outputNew
I would appreciate your help, thank you
RudiC
June 12, 2018, 10:42am
2
Welcome to the forum.
Does the above work, or what goes wrong? And, add some sample input data plus your OS, shell, and sed
versions.
dlesny
June 12, 2018, 11:29am
3
Hi yes it goes wrong
sed: -e expression #1, char 23: extra characters after command
It works if I only run first part without: , /Finished:/
Tried already without coma, with d; but also fails.
I am running it on Centos7 through Jenkins. GNU bash 4.2.46 x86_64, sed 4.2.2
---------- Post updated at 04:29 PM ---------- Previous update was at 03:51 PM ----------
Got It. Took me several hours but here it is:
sed -n '/\(Started by\|Building in\|Finished:\)/p' ${OUTPUT_DIR}/all_job_output > ${OUTPUT_DIR}/all_job_outputNew
Instead of doing plus one line I have searched for 3rd expression "Building in"
Thanks anyway.
1 Like
RudiC
June 12, 2018, 11:50am
4
Thanks for sharing.
There were two things wrong with your first command: a ,
in lieu of a ;
, and a p
command missing after second address expression. Try
sed -n '/Started by user/, +1p; /Finished:/p' file
Please not the +1
address form is not standard but a GNU extension.
1 Like