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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-16-2012, 05:14 PM
|
#1
|
Member
Registered: Jul 2009
Posts: 44
Rep:
|
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?
|
|
|
08-16-2012, 05:17 PM
|
#2
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
|
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.
|
|
|
08-16-2012, 05:25 PM
|
#3
|
Member
Registered: Jul 2009
Posts: 44
Original Poster
Rep:
|
Quote:
Originally Posted by sycamorex
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.
|
|
|
08-16-2012, 05:31 PM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
|
Try:
Code:
awk '$1 ~/::/ {print $1}' file
|
|
1 members found this post helpful.
|
08-16-2012, 05:40 PM
|
#5
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
|
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.
|
08-16-2012, 05:45 PM
|
#6
|
Member
Registered: Jul 2009
Posts: 44
Original Poster
Rep:
|
Many thanks.. That is exactly what I wanted. 
|
|
|
08-16-2012, 05:46 PM
|
#7
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
|
What about that:
Code:
awk '{for (i=1;i<=NF;i++) if ($i ~/[a-z]::/) print $i}' file
|
|
1 members found this post helpful.
|
08-16-2012, 05:49 PM
|
#8
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
|
Quote:
Originally Posted by rohit.dhaval1
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
|
|
|
08-16-2012, 08:31 PM
|
#9
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
How about a little gem (pun):
Code:
ruby -ne 'puts $_.scan(/(\w+(::\w+)+)/)[0][0]' file
|
|
1 members found this post helpful.
|
08-21-2012, 08:00 PM
|
#10
|
Member
Registered: Jul 2009
Posts: 44
Original Poster
Rep:
|
thank you all
|
|
|
08-22-2012, 09:08 AM
|
#11
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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.
|
All times are GMT -5. The time now is 01:15 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|