LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-16-2012, 05:14 PM   #1
rohit.dhaval1
Member
 
Registered: Jul 2009
Posts: 39
Blog Entries: 2

Rep: Reputation: 0
How do I list 'WORDS' containing a specific character? awk,sed,grep?


I have a large file containing thousands of lines, I want to list only strings containig "::".

File example:
Data::Compare 1.22 (1.2101 < 1.22)::
Data:umper::Concise 2.020 (1.100 < 2.020)
Hash::Merge 0.12 (0.10 < 0.12)::
Path::Class 0.18 (0.16 < 0.18)::
Service-now INC10056109 Install Perl Sort::Topological module Primary 0.02 5.8.8, 5.14.0 TESTING ::
String::Escape 0::
String::Escape 0::
Data::Compare 0::
----------------------
Expected output:
Data::Compare
Data:umper::Concise
Hash::Merge
Path::Class
Sort::Topological


How can I achieve it?
 
Old 08-16-2012, 05:17 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,563
Blog Entries: 1

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
What about the line starting with Service? It does contain :: Or the one starting with Path?
What's wrong with it?
You need to be more specific

Last edited by sycamorex; 08-16-2012 at 05:24 PM.
 
Old 08-16-2012, 05:25 PM   #3
rohit.dhaval1
Member
 
Registered: Jul 2009
Posts: 39
Blog Entries: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by sycamorex View Post
What about the line starting with Service? It does contain :: Or the one starting with Path?
What's wrong with it?
You need to be more specific
No matter how the line starts or ends, all I need is list of words containing '::' in it.
 
Old 08-16-2012, 05:31 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,563
Blog Entries: 1

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
Try:
Code:
awk '$1 ~/::/ {print $1}' file
 
1 members found this post helpful.
Old 08-16-2012, 05:40 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,563
Blog Entries: 1

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
My solution above may work or may not. It's not exactly what I think you're after.

Is that what you want?
Code:
Data::Compare
Data:umper::Concise
Hash::Merge
Path::Class
Sort::Topological
String::Escape
String::Escape
Data::Compare
 
1 members found this post helpful.
Old 08-16-2012, 05:45 PM   #6
rohit.dhaval1
Member
 
Registered: Jul 2009
Posts: 39
Blog Entries: 2

Original Poster
Rep: Reputation: 0
Many thanks.. That is exactly what I wanted.
 
Old 08-16-2012, 05:46 PM   #7
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,563
Blog Entries: 1

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
What about that:

Code:
awk '{for (i=1;i<=NF;i++) if ($i ~/[a-z]::/) print $i}' file
 
1 members found this post helpful.
Old 08-16-2012, 05:49 PM   #8
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,563
Blog Entries: 1

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
Quote:
Originally Posted by rohit.dhaval1 View Post
Many thanks.. That is exactly what I wanted.
Please note that the solution from post #4 will NOT give you the output from post #5
Try the solution from post #7
 
Old 08-16-2012, 08:31 PM   #9
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
How about a little gem (pun):
Code:
ruby -ne 'puts $_.scan(/(\w+(::\w+)+)/)[0][0]' file
 
1 members found this post helpful.
Old 08-21-2012, 08:00 PM   #10
rohit.dhaval1
Member
 
Registered: Jul 2009
Posts: 39
Blog Entries: 2

Original Poster
Rep: Reputation: 0
thank you all
 
Old 08-22-2012, 09:08 AM   #11
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Code:
$ grep -Eo '\b[^ ]+::[^ ]+\b' inputfile.txt
Data::Compare
Data:umper::Concise
Hash::Merge
Path::Class
Sort::Topological
String::Escape
String::Escape
Data::Compare
And please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, bolding, colors, or other fancy formatting.

If you go into the advanced editing box, there's also an option allowing you to turn off the smiley faces.
 
1 members found this post helpful.
  


Reply

Tags
awk, grep, linux, sed, shell


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sed replacing a specific character with a specific number ieatbunnies Linux - Newbie 2 11-04-2010 10:14 AM
replace specific character after specific line by awk Syed Tarique Moin Programming 2 07-19-2010 01:47 PM
grep, sed, awk or tr - searching words in a string hal8000b Programming 2 03-06-2009 08:04 PM
Delete specific Range of lines Using sed , awk, grep etc. joyds219 Linux - Newbie 4 03-28-2008 08:59 AM
Need to strip words from front of line. sed/awk/grep? joadoor Linux - Software 6 08-28-2006 04:39 AM


All times are GMT -5. The time now is 12:16 PM.

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