Issues while pattern matching using grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Issues while pattern matching using grep
# 1  
Old 11-08-2012
Issues while pattern matching using grep

Hi,

I have a file f1 wi the following data

f1.txt
========

Report ID
Report Name
-----------------------------------------------------------------

Post Requests : 2 Post successes : 2

=============================================

I need to search for the word "Post" and copy them in a different file with the out put as below:

output.txt should be
================
Post Requests:2
Post successes:2

Please help me on this!
# 2  
Old 11-08-2012
Hi

Code:
$ sed -n '/Post /s/Post s/\n&/p' file
Post Requests : 2
Post successes : 2


Guru.
# 3  
Old 11-08-2012
Try this one also
Code:
awk '/Post/{gsub(/Post/,"\nPost");sub(/^\n/,"");print;}' f1

Thank you,
Senthil
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep file starting from pattern matching line

I have a file with a list of references towards the end and want to apply a grep for some string. text .... @unnumbered References @sp 1 @paragraphindent 0 2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez, Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies

2. Shell Programming and Scripting

Grep log file to get line above matching pattern

Hi, I have a log file that looks like this "delete" : { "_type" : "cl", "_id" : "1000600000000562636", "_version" : 1, "status" : 200, "found" : false } }, { "delete" : { "_type" : "cl", "_id" : "1000600000000562643", ... (4 Replies)
Discussion started by: wahi80
4 Replies

3. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

4. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

5. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

6. Shell Programming and Scripting

Understanding pattern matching used in a grep command

I have the following code. I want to remove the --sort=num/num/... and am using grep to exclude it as shown below: I have a bit of problem figuring out the use of - at the front echo "--sort=4/5/6" | grep -ivE '-((sort|group)=+/+(/+)*)$' Now suppose I want to remove --quiet I can... (7 Replies)
Discussion started by: kristinu
7 Replies

7. Homework & Coursework Questions

shell script that can create, monitor the log files and report the issues for matching pattern

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write an automated shell program(s) that can create, monitor the log files and report the issues for matching... (0 Replies)
Discussion started by: itian2010
0 Replies

8. UNIX for Dummies Questions & Answers

grep only word matching the pattern

Hi gurus, A file contains many words in format "ABC.XXXX.XXXX.X.GET.LOG" (X->varying). Now my shell script want this list (only words in formatABC.XXXX.XXXX.X.GET.LOG ) to continue the process. Pls help me. Thanks, Poova. (8 Replies)
Discussion started by: poova
8 Replies

9. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

10. Shell Programming and Scripting

perl pattern matching vs. grep

I originally had a shell script that did a grep 10 times to pull out the number of times a certain pattern occured in a file: ie... aOccurances=`grep aPattern file|wc -l` bOccurances=`grep bPattern file|wc -l` ... ... ... fOccurances=`grep fPattern file|wc -l` As the file got bigger with... (0 Replies)
Discussion started by: junkmail426
0 Replies
Login or Register to Ask a Question