Want to separate one string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to separate one string
# 1  
Old 09-20-2013
Want to separate one string

Hello friends.

I have on file with following data

Code:
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.?

Last edited by Scrutinizer; 09-20-2013 at 03:06 PM.. Reason: code tags
# 2  
Old 09-20-2013
Use awk:
Code:
awk '/pending/{print n}{n=$0}' file

# 3  
Old 09-20-2013
Try:
Code:
sed -n 'N;/pending/p'  file

or
Code:
sed -n 'N;/pending/P' file

# 4  
Old 09-20-2013
Or using gnu grep:
Code:
grep -B1 pending file

From grep manual page:
Code:
-B NUM, --before-context=NUM
       Print NUM lines of leading context before matching lines.  Places a line containing -- between contiguous groups of matches.

# 5  
Old 09-20-2013
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

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

How we can separate this line also by using a single querry.?
# 6  
Old 09-20-2013
Try:
Code:
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.

# 7  
Old 09-20-2013
Code:
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

This User Gave Thanks to in2nix4life For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

2. Shell Programming and Scripting

Separate string based on delimiter

Hi, for fd in $(grep "/tmp/" hello.properties)The grep gives me the below output: deploydir=/tmp/app1/dfol prodir= /tmp/hello/prop ...... Now i want to store /tmp/app1/dfol then /tmp/hello/prop in a variable so that i can check if those folders files exists or not. The delimiter would... (4 Replies)
Discussion started by: mohtashims
4 Replies

3. UNIX for Advanced & Expert Users

Parse (delimited string) key-value pairs in a column into separate lines

Hi experts, e.g. i/p data looks like 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified|| o/p data should like - row1: 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified ... (1 Reply)
Discussion started by: sumoka
1 Replies

4. Shell Programming and Scripting

Get string between quotes separate by commas

I'm a beginner with shell and tried to do this per hours and everytinhg gives different want i do. So I have a lot of file in *.csv ( a.csv, b.csv ...) in each file csv , it has some fields separeted by commas. ----- "joseph";"21","m";"groups";"j.j@gmail.com,j.j2@hotmail.com"... (6 Replies)
Discussion started by: flaviof
6 Replies

5. Shell Programming and Scripting

Trying to take a string and break each letter into a separate variable

I am trying to make a script that takes a word and each letter up and turns it into a separate variable. My code currently does not work but I feel I just need to tweak one thing that I am unsure of. (ex: if forum was typed in letter1=f; letter2=o; letter3=r;...) Thank you count=1; ... (7 Replies)
Discussion started by: crimputt
7 Replies

6. Shell Programming and Scripting

Need help with shell, trying to append or separate values in a string

Ok. I for the life of me cant figure out how to do this. I need Help. So here is what I'm trying to do. I have a block of text. They are FIPS codes for counties. Below is the block. There are probably a few ways to do this. The first line starting with ARC021....... this line is a list of... (2 Replies)
Discussion started by: chagan02
2 Replies

7. Shell Programming and Scripting

Matching a string (zip code) from a list in a separate file

I have a list of postal addresses and I need to pull the records that match a list of zip codes in a separate file. The postal addresses are fixed width. The zip code is located in character position 149-157. Something better than: cat postalfile.txt | grep -f zipcodes.txt would be great. $... (8 Replies)
Discussion started by: sitney
8 Replies

8. Shell Programming and Scripting

Separate String Shell Script

Hi guys, I am a beginner in shell script.. How can I separate a string coming from a parameter in spaces ? Ex: input: test.sh abcd output: a b c d Thanks Dusse (15 Replies)
Discussion started by: dusse
15 Replies

9. UNIX for Dummies Questions & Answers

to separate values from a string

Hi I would like to take input from user like username/password@connectstring I should be able to cut the username and password and connect string for example if someone enters like sam/sammy@ora1 my program should take sam as username sammy as password and ora1 as connectstring and... (3 Replies)
Discussion started by: ssuresh1999
3 Replies

10. Shell Programming and Scripting

Separate string

i am a biginner of shell scripting.please help me how can i seperate a string in two parts.eg.user given sting is"oi2ehello".i want to make 2 string string1=oi2e and string2=hello (3 Replies)
Discussion started by: arghya_owen
3 Replies
Login or Register to Ask a Question