Sample Header Ad - 728x90

How to keep previous and current line if the previous line contains common text?

-2 votes
4 answers
95 views
How to keep previous and current line if the previous line contains common text? I have a main file like this: Hello_world Anna Frank Jeremy Hello_earth Jessie James I would want 3 output files like this: **Output file 1** (Only has the string with the previous hello) Hello_world,Anna Hello_earth,Jessie **Output file 2** (Only has the string WITHOUT previous hello) Frank Jeremy James **Output file 3** (Only has the string with the previous hello and including Hi to string without hello from previous line ) Hello_world,Anna Hello_earth,Jessie Hi,Frank Hi,Jeremy Hi,James I have tried using grep and awk but was not able to get the desired output
Asked by jovicue (11 rep)
Feb 8, 2023, 12:07 AM
Last activity: Apr 17, 2024, 06:01 PM