|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Print only matching words
Hi All,
I have searched the forum and tried to print only matching(pattern) words from the file, but its printing entire line. I tried with grep -w. I am on sunsolaris. Eg: cat file A|A|F1|F2|A|F3|A A|F10|F11|F14|A| F20|A|F21|A|F25 I have to search for F[0-9][0-9] (F followed by numbers) and print distinct F1,F2,F3,F4....etc Thanks all for your time and help. |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Code:
awk -F"|" '{for (i=1;i<=NF;i++){if ($i~/^F/){print $i}}}' infile |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Thanks!!
|
|
#4
|
||||
|
||||
|
You could also try: Code:
grep -o 'F[0-9]*' file or Code:
egrep -o 'F[0-9]*' file -o, --only-matching Show only the part of a matching line that matches PATTERN. ---------- Post updated 06-12-10 at 00:00 ---------- Previous update was 06-11-10 at 23:54 ---------- Oh, I see neither grep nor egrep support the -o option ![]() Man Page for grep (OpenSolaris Section 1) - The UNIX and Linux Forums Man Page for egrep (OpenSolaris Section 1) - The UNIX and Linux Forums |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
On Solaris /usr/xpg4/bin/grep probably supports -o option.
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
That would be cool
Let's see if gsjdrr can confirm that... |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed/awk: Delete matching words leaving only the first instance | GrinningArmor | Shell Programming and Scripting | 2 | 01-20-2010 03:31 AM |
| Matching words in Perl | monika | Shell Programming and Scripting | 2 | 02-14-2009 04:20 AM |
| How to from grep command from a file which contains matching words? | johnl | Shell Programming and Scripting | 4 | 07-29-2008 01:44 AM |
| matching words using regular expressions | bishweshwar | UNIX for Advanced & Expert Users | 1 | 12-27-2007 09:28 AM |
| getting file words as pattern matching | arunkumar_mca | Programming | 5 | 05-31-2005 03:28 AM |
|
|