Want to separate one string

Hello friends.

I have on file with following data

Jhon 
Status: Form successfully submitted
Maria
Status:Form successfully submitted
Shyne 
Status: Form submission pending.
Liken 
Status:Form successfully submitted
David
Status:Form successfully submitted
Rich
Status: Form submission pending.

I want to saperate those users for which form submission is pending.
in above example they are Shyne and Rich

How can i use grep command here. Is there any other command for this.?

Use awk:

awk '/pending/{print n}{n=$0}' file

Try:

sed -n 'N;/pending/p'  file

or

sed -n 'N;/pending/P' file

Or using gnu grep:

grep -B1 pending file

From grep manual page:

-B NUM, --before-context=NUM
       Print NUM lines of leading context before matching lines.  Places a line containing -- between contiguous groups of matches.

here i see everyone have used a same keyword "pending" for separation.
If we want to use multiple keywords then how will be the command.?
for example if there is one more entry in table like

Ron
Status: Form submission is complete but application fees are not submitted

How we can separate this line also by using a single querry.?

Try:

awk '{getline x; $0=$0 "\t" x;} !/success/' file
Shyne     Status: Form submission pending.
Ron       Status: Form submission is complete but application fees are not submitted
Rich      Status: Form submission pending.
cat file

Jhon
Status: Form successfully submitted
Maria
Status:Form successfully submitted
Shyne
Status: Form submission pending.
Liken
Status:Form successfully submitted
David
Status:Form successfully submitted
Rich
Status: Form submission pending.
Ron
Status: Form submission is complete but application fees are not submitted


awk '/pending|application/{if(a && a !~ /pending|application/) print a; print}{a=$0}' file

Shyne
Status: Form submission pending.
Rich
Status: Form submission pending.
Ron
Status: Form submission is complete but application fees are not submitted
1 Like

I did not test them them, but unless your form blocks users who include "pending", "application", or "success" as substrings, then, in my opinion, every suggestion so far is unsuitable.

Even if you consider such an event a remote possibility, if this is a critical task, such unlikely scenarios should be properly handled.

It seems that Scrutinizer's sed approach can be easily fortified using \n to segregate the user name from the status text.

Regards,
Alister