Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echo in shell script, all grep's printing on the same line

Status
Not open for further replies.

linuxMaestro

Instructor
Jan 12, 2004
183
US
I have a simple shell script
echo `cat file | grep hello`

but it prints the output like
hello katie hello sam hello ralph hello linus

but when I run it from the command line it prints like this...
hello katie
hello sam
hello ralph
hello linus

Which is how I want the shell script to print it.

How can I get the shell script to print it that way?
 
Just do
Code:
cat file | grep hello
in your script.

--
 
If you want that echo keep new lines, use double quote "
[tt]Lines=`grep hello file`
echo "$Lines"[/tt]
or
[tt]echo "`cat file | grep hello`"[/tt]
or
[tt]grep hello file[/tt]




Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top