The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 01:45 PM
First letter of each Word from a line maxmave Shell Programming and Scripting 5 04-15-2008 07:52 PM
return a word between two words bryan UNIX for Dummies Questions & Answers 4 05-23-2006 01:56 PM
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 09:35 PM
How to replace a word with a series of words in a file brap45 Shell Programming and Scripting 2 02-21-2006 02:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
venu_eie venu_eie is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 5
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
  #2 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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 11:26 AM.. Reason: Show which lines are input
  #3 (permalink)  
Old 03-18-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,854
With Z-Shell:

Code:
print ${(M)$(<file)##*abc*}
  #4 (permalink)  
Old 03-19-2008
venu_eie venu_eie is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 5
Hi era,

Your solution is in perl, I need it in unix.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0