![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 !! |
|
|
||||
| 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 12:23 PM |
| grep a word and display its column | Orbix | UNIX for Dummies Questions & Answers | 1 | 12-24-2007 04:32 PM |
| how to move word by word on command line | pbsrinivas | UNIX for Dummies Questions & Answers | 1 | 11-23-2007 02:17 AM |
| to display the word containing all of aeiou in a file. | arunsubbhian | UNIX for Dummies Questions & Answers | 1 | 09-09-2007 12: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 03:29 AM |
|
|
Submit Tools | LinkBack | Thread Tools | 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 |
| Forum Sponsor | ||
|
|
|
|||
|
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.
|
|||
| Google The UNIX and Linux Forums |