The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 06-20-2007
anbu23 anbu23 is offline
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by knowledge_gain View Post
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
Code:
sed -n -e "s/\(Hello\)/\1\\
/gp" file | sed -n -e "s/.*\(Hello\).*/\1/p"
Reply With Quote