The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
matching a letter in a word Furqan_79 Shell Programming and Scripting 2 06-05-2008 10:45 AM
First letter of each Word from a line maxmave Shell Programming and Scripting 5 04-15-2008 04:52 PM
return a word between two words bryan UNIX for Dummies Questions & Answers 4 05-23-2006 10:56 AM
how to find capital letter names in a file without finding words at start of sentence kev269 Shell Programming and Scripting 1 04-10-2006 06:35 PM
How to replace a word with a series of words in a file brap45 Shell Programming and Scripting 2 02-20-2006 10:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-18-2008
Registered User
 

Join Date: Aug 2007
Posts: 5
Stumble this Post!
How to filter the words, if that word contains the expected letter

Hi,

I am trying to filter the words from a file which contain 'abc'. But I am unable to. Could any one help me.

For eg: The file contents are

123ab 12hnj1 123abc456 123cgbcahjkf23 23134abchfhj43 gc32abc abc1 2abc3 sd uiguif fhwe 21242 uh123 jkcas124d123 u3hdbh23u ffsd8

Output expecting is :
123abc456 23134abchfhj43 gc32abc abc1
2abc3

Regards
Venu
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-18-2008
era
Guest
 

Posts: n/a
Stumble this Post!
Your example is not very clear. You mean, extract and print those tokens which contain the string "abc"?

Code:
vnix$ perl -lane 'print join (" ", grep { /abc/ } @F)'
foo fabci canbc cabca fnabca 123ab23c babco swill <- input
fabci cabca fnabca babco
snort abc foo <- input
abc
^D
Do you want to preserve newlines? (This solution does.) What about spaces between the tokens? (This solution normalizes them to one space between each.)

Last edited by era; 03-18-2008 at 07:26 AM. Reason: Show which lines are input
Reply With Quote
  #3 (permalink)  
Old 03-18-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,536
Stumble this Post!
With Z-Shell:

Code:
print ${(M)$(<file)##*abc*}
Reply With Quote
  #4 (permalink)  
Old 03-19-2008
Registered User
 

Join Date: Aug 2007
Posts: 5
Stumble this Post!
Hi era,

Your solution is in perl, I need it in unix.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0