![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find a word in a file, and change a word beneath it ?? | vikas027 | Shell Programming and Scripting | 2 | 02-13-2008 04:23 PM |
| grep a word and display its column | Orbix | UNIX for Dummies Questions & Answers | 1 | 12-24-2007 08:32 PM |
| how to move word by word on command line | pbsrinivas | UNIX for Dummies Questions & Answers | 1 | 11-23-2007 06:17 AM |
| to display the word containing all of aeiou in a file. | arunsubbhian | UNIX for Dummies Questions & Answers | 1 | 09-09-2007 03:57 PM |
| Can a shell script pull the first word (or nth word) off each line of a text file? | tricky | Shell Programming and Scripting | 5 | 08-17-2006 06:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
how to grep for a word and display only the word
Hi,
When we "grep" for a word in a file, it returns the lines containing the word that we searched for. Is there a way to display only the words and not the entire line containing them. Thanks Ananth |
|
||||
|
Using grep -o in linux, it gives the list wherever the pattern appears. The file
input_file has "Hello World Hi Hello Hello Hello Hello Bye " for eg: grep -o "Hello" input_file Hello Hello Hello Hello Hello sed -n -e "s/.*\(Hello\).*/\1/p" input_file But in using sed, it prints One Hello per line, becoz of \1. Is it any other way to print same as in linux. TIA |
|
||||
|
Quote:
Code:
sed -n -e "s/\(Hello\)/\1\\ /gp" file | sed -n -e "s/.*\(Hello\).*/\1/p" |
|
||||
|
It would be better if you use -w option to grep.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| linux, solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|