![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| searching one pattern in file and also counting | ksr.test | UNIX for Advanced & Expert Users | 8 | 10-20-2008 01:03 PM |
| I am trying to find pattern between two words but unable to get that pattern.. | ksr.test | UNIX for Advanced & Expert Users | 7 | 09-09-2008 10:34 AM |
| searching pattern in another file and print | cdfd123 | Shell Programming and Scripting | 2 | 10-26-2007 03:30 AM |
| searching for a pattern in a file and forwarding result to another | ocelot | UNIX for Advanced & Expert Users | 7 | 01-22-2007 12:39 PM |
| getting file words as pattern matching | arunkumar_mca | High Level Programming | 5 | 05-31-2005 04:28 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi all,
I would like to print words in a file seperated by whitespaces containing a specific pattern like "=" e.g. I have a file1 containing strings like %cat file1 The= some= in wish= born <eof> .I want to display only those words containing = i.e The= , some=,wish= when i grep for pattern "=" in file1 , I get the entire line.. So I decided to loop like for words in $( grep -x "=" file1) do # How do I print only those words containing = here done or is there a better way? |
|
||||
|
awk Code:
# awk '{for(i=1;i<=NF;i++){if ($i ~/=$/) {print $i}}}' file
The=
some=
wish=
alternative solution with Python Code:
for line in open("file"):
line=line.strip().split()
for items in line:
if items.endswith("="):
print items,
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|