Want to search for a every paragraph that has a certain string and return some string from that paragraph
2
votes
1
answer
57
views
/* ----------------- WANT TO RETURN1 ----------------- */
machine: some value
server: WANT TO RETURN1
owner: some value
notification: some value
informatica: some value
sap: some value
group: This line contains a3 but can have space and characters
/* ----------------- WANT TO RETURN2 ----------------- */
server: WANT TO RETURN2
machine: some value
owner: some value
notification: some value
informatica: some value
sap: some value
group: This line contains a1 but can have space and characters
unix: some value
windows: some value
aws: some value
sap1: some value
/* ----------------- WANT TO RETURN3 ----------------- */
owner: some value
machine: some value
server: WANT TO RETURN3
notification: some value
informatica: some value
sap: some value
group: This line contains a1 but can have space and characters
/* ----------------- WANT TO RETURN4 ----------------- */
server: WANT TO RETURN4
machine: some value
owner: some value
notification: some value
informatica: some value
sap: some value
group: This line contains a2 but can have space and characters
unix: some value
windows: some value
aws: some value
sap1: some value
Need to do with linux shell script if possible.
I have some data in unix file as above.
I have a file with multiple values for _STRING_TO_SEARCH
_ like
job.txt
:
a1
a2
a3
Example -
I want to run a for loop for each value of _STRING_TO_SEARCH
_ and capture both _STRING_TO_SEARCH
_ and server:
value for that paragraph
Desired output -
group: a1
server: WANT TO RETURN2
server: WANT TO RETURN3
group: a2
server: WANT TO RETURN4
group: a3
server: WANT TO RETURN1
In each paragraph number of rows will vary and fields server: WANT TO RETURN
and group:
. This line contains a1
but can have space or characters can can occur on any row.
Asked by user9797
(23 rep)
Jul 17, 2025, 11:12 PM
Last activity: Jul 18, 2025, 11:08 AM
Last activity: Jul 18, 2025, 11:08 AM