Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-24-2006, 01:08 AM   #1
Registered: Dec 2005
Posts: 48

Rep: Reputation: 15
finding multiple occurances of a pattern

I wish to find multiple occurances of the pattern "Connection <some string> = {".

Here except <some string>, all the characters in the
above pattern are constant.and I wish to find all such patterns in a file.

Please help me to solve this.

Old 05-24-2006, 01:40 AM   #2
Registered: Mar 2005
Location: india
Distribution: FC4, Debian Etch
Posts: 67

Rep: Reputation: Disabled
Try this:

$ sed -n -e '/Connection \(.*\) = {/p' pattern_file
Old 05-24-2006, 01:53 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680
You can use the grep command.
If all of the patterns occur on the same line and are not split, that makes things easier.
grep 'Connection [[:alnum:]]-:]* = {' filename

Look at what characters can occur in the <some string>. If they don't include a space or equals sign, you can use:
grep 'Connection .* = {' filename

If the pattern can be split across one or more lines, then you may need to use sed
Old 05-24-2006, 04:23 PM   #4
LQ Newbie
Registered: May 2005
Distribution: suse 9.1 Pro
Posts: 29

Rep: Reputation: 15
If possible, also try kfind - seems to be a good GUI solution.

Edit - doesn't appear to work for string occurences in plain text files - bummer!

Last edited by sidesec; 05-24-2006 at 05:01 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 07:17 AM
how many occurances of a substring are they n a string linuxmandrake Programming 1 04-11-2006 03:02 AM
Finding multiple files with different extensions ExoZagNoid Linux - Newbie 1 01-18-2006 04:33 AM
Counting occurances in file stefaandk Linux - General 1 08-13-2005 09:55 AM
replacement with sed: replace pattern with multiple lines Hcman Programming 5 11-18-2004 08:40 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration