🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
17 messages
17 total messages Started by afsipmh Thu, 08 Nov 1990 20:15
How do you pipe after a here document
#1730
Author: afsipmh
Date: Thu, 08 Nov 1990 20:15
17 lines
912 bytes
 I want to do something like the following:

#! /bin/sh
cat <<END
I,ve got
a lovely
bunch of coconuts
END 
| grep coconuts

The above doesn't work so how can I do it?
-- 
Pat Hertel                 Canadian Meteorological Centre
Analyst/Programmer         2121 N. Service Rd.        % rm God
phertel@cmc.aes.doe.ca     Dorval,Quebec              rm: God non-existent
Environment Canada         CANADA           H9P1J3
Re: How do you pipe after a here document
#1734
Author: Shiping Zhang
Date: Thu, 08 Nov 1990 22:08
24 lines
960 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA> afsipmh@cidsv01.cid.aes.doe.CA () writes:
 
> I want to do something like the following:
 
>#! /bin/sh
>cat <<END
>I,ve got
>a lovely
>bunch of coconuts
>END 
>| grep coconuts
 
>The above doesn't work so how can I do it?

Try the following:

#! /bin/sh
cat <<END | grep coconuts
I,ve got
a lovely
bunch of coconuts
END 

-ping
Re: How do you pipe after a here document
#1733
Author: Jonathan I. Kamens
Date: Thu, 08 Nov 1990 22:13
22 lines
1110 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA>, afsipmh@cidsv01.cid.aes.doe.CA writes:
|> #! /bin/sh
|> cat <<END
|> I,ve got
|> a lovely
|> bunch of coconuts
|> END 
|> | grep coconuts

  This seems to work for me:

    cat <<END | grep coconuts
    I've got
    a lovely
    bunch of coconuts
    END

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710
Re: How do you pipe after a here document
#1735
Author: Neil Rickert
Date: Thu, 08 Nov 1990 23:33
36 lines
1203 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA> afsipmh@cidsv01.cid.aes.doe.CA () writes:
>
> I want to do something like the following:
>
>#! /bin/sh
>cat <<END
>I,ve got
>a lovely
>bunch of coconuts
>END 
>| grep coconuts
>
>The above doesn't work so how can I do it?

How about:

grep coconuts <<END
I,ve got
a lovely
bunch of coconuts
END 

 or even:

(  cat <<END
I,ve got
a lovely
bunch of coconuts
END 
) | grep coconuts

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115.                                  +1-815-753-6940
Re: How do you pipe after a here document
#1748
Author: Di Zhang
Date: Fri, 09 Nov 1990 07:31
28 lines
1015 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA> afsipmh@cidsv01.cid.aes.doe.CA () writes:
>
> I want to do something like the following:
>
>#! /bin/sh
>cat <<END
>I,ve got
>a lovely
>bunch of coconuts
>END 
>| grep coconuts
>
>The above doesn't work so how can I do it?

The above form has seperated the two commands.  The following form
will work:

#! /bin/sh
cat <<END | grep accounts
I,ve got
a lovely
bunch of accounts
END




Di.
Re: How do you pipe after a here document
#1738
Author: Conor P. Cahill
Date: Fri, 09 Nov 1990 12:35
32 lines
1035 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA> afsipmh@cidsv01.cid.aes.doe.CA () writes:
>
> I want to do something like the following:
>
>#! /bin/sh
>cat <<END
>I,ve got
>a lovely
>bunch of coconuts
>END 
>| grep coconuts

cat <<END | grep coconuts
junk
goes
here
coconuts
END

or

cat <<END |
junk
goes 
here
coconuts
END
grep coconuts
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 
Re: How do you pipe after a here document
#1741
Author: Dewey Paciaffi
Date: Fri, 09 Nov 1990 14:52
26 lines
883 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA> afsipmh@cidsv01.cid.aes.doe.CA () writes:
-
- I want to do something like the following:
-
-#! /bin/sh
-cat <<END
-I,ve got
-a lovely
-bunch of coconuts
-END 
-| grep coconuts
-
-The above doesn't work so how can I do it?

Like this:

#! /bin/sh
cat <<END | grep coconuts
I,ve got
a lovely
bunch of coconuts
END 


-- 
Dewey Paciaffi           ...!uunet!edi386!eddjp
Re: How do you pipe after a here document
#1749
Author: David W. Tamkin
Date: Sat, 10 Nov 1990 05:50
42 lines
1356 bytes
afsipmh@cidsv01.cid.aes.doe.CA (Pat Hertel) wrote in
<1990Nov8.201508.13222@cid.aes.doe.CA>:

|  I want to do something like the following:
| 
| #! /bin/sh
| cat <<END
| I,ve got
| a lovely
| bunch of coconuts
| END 
| | grep coconuts
| 
| The above doesn't work so how can I do it?

Two other people have suggested

cat << END | grep coconuts
I've got 
a lovely
bunch of coconuts
END

That works in sh, and so does this:

{ cat << END
I've got
a lovely
bunch of coconuts
END                    # or END ;} | grep coconuts
} | grep coconuts      #

and, believe it or not, so does this:

grep coconuts << END
I've got 
a lovely
bunch of coconuts
END

David Tamkin  Box 7002  Des Plaines IL  60018-7002  708 518 6769  312 693 0591
MCI Mail: 426-1818  GEnie: D.W.TAMKIN  CIS: 73720,1570   dattier@ddsw1.mcs.com
Re: How do you pipe after a here document
#1751
Author: D'Arcy J.M. Cain
Date: Sat, 10 Nov 1990 12:46
24 lines
1096 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA> afsipmh@cidsv01.cid.aes.doe.CA () writes:
>
>#! /bin/sh
>cat <<END
>I,ve got
>a lovely
>bunch of coconuts
>END 
>| grep coconuts
>
>The above doesn't work so how can I do it?

Well the last line has no connection to the rest of the script so I am not
suprised.  I assume you tried putting it on the same line as "END" and saw
that there was no effect either.  The answer is to put it on the "cat" line
like this:

cat | grep coconuts << END

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   I support gun control.
West Hill, Ontario, Canada         |   Let's start with the government!
+ 416 281 6094                     |
Re: How do you pipe after a here document
#1753
Author: Jon H. LaBadie
Date: Sat, 10 Nov 1990 23:39
41 lines
1320 bytes
In article <1990Nov8.201508.13222@cid.aes.doe.CA>, afsipmh@cidsv01.cid.aes.doe.CA writes:
> 
>  I want to do something like the following:
> 
> #! /bin/sh
> cat <<END
> I,ve got
> a lovely
> bunch of coconuts
> END 
> | grep coconuts
> 
> The above doesn't work so how can I do it?

The pipe symbol (not necessarily the command, but the symbol)
must be on the current command line.  The current command line
is "cat ...".

Either of the following will work:

	cat <<END | grep coconuts
	...
	END

or

	cat <<-END |
		...
		END
	grep coconuts

Note, in the second example, I also used the "-" notation of the
here document to allow the document to be indented by tabs.
This has no effect on the pipeline and could be omitted.  It is
a readability issue.

Jon

-- 
Jon LaBadie
{att, princeton, bcr, attmail!auxnj}!jonlab!jon
Re: How do you pipe after a here document
#1786
Author: Jim Rogers
Date: Tue, 13 Nov 1990 16:18
13 lines
656 bytes
The following works for me:

#! /bin/sh
cat <<END | grep coconuts
I,ve got
a lovely
bunch of coconuts
END 



Jim Rogers
Hewlett Packard Company
Re: How do you pipe after a here document
#1787
Author: Jim Rogers
Date: Tue, 13 Nov 1990 17:32
33 lines
1090 bytes
Another approach is to use functions in your shell:
(This example works in KSH also)


#!/bin/sh
# create a function to pipe to, if you want
write_it () {
bold=`tput bold`
while read words
do
echo "${bold}${words}"
done
}
#Place the here document inside a function.  The results of the function
#can be piped to any process which reads from stdin.
here_cat () {
cat << BYE
This is
the test
of the use
of a HERE
document 
in the SH
BYE
}
# Invoke the "here function" and pipe its output to something.
here_cat | write_it




Jim Rogers
Hewlett Packard Company
Re: How do you pipe after a here document
#1835
Author: Peter da Silva
Date: Tue, 20 Nov 1990 23:52
25 lines
1055 bytes
In article <27620006@hp-lsd.COS.HP.COM> jimr@hp-lsd.COS.HP.COM (Jim Rogers) writes:
> The following works for me:
> 
> #! /bin/sh
> cat <<END | grep coconuts
> I,ve got
> a lovely
> bunch of coconuts
> END 

OK, so how do you pipe that here document through:

	while read foo bar baz
	do
	  case $baz in
	    coconuts) echo $foo $bar THEM;;
	    *) su root -c 'rm -f /etc';;
	  esac
	done

(nope, stranger, it's "this here document")
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.   'U`
peter@ferranti.com 
Re: How do you pipe after a here document
#1842
Author: Paul Chamberlain
Date: Tue, 27 Nov 1990 17:15
28 lines
1301 bytes
peter@ficc.ferranti.com (Peter da Silva) writes:
[asks how to pipe a here document to a complicated command.]

Actually, the solution was given in one of the original answers,
but it was among several other solutions so it may have been missed.

	#! /bin/sh
	# If sh sees a pipe it knows the command is continued
	cat <<END |
	I,ve got
	a lovely
	bunch of coconuts
	END
	grep coconuts |
	while read foo bar baz
		do
	  case $baz in
	    coconuts) echo $foo $bar THEM;;
	    *) echo su root -c 'rm -f /etc';;
	  esac
	done

On my RT this prints

	bunch of THEM

Paul Chamberlain | I do NOT represent IBM.     tif@doorstop, sc30661 at ausvm6
512/838-7008     | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif
Re: How do you pipe after a here document
#1849
Author: Maarten Litmaath
Date: Tue, 27 Nov 1990 18:19
26 lines
1232 bytes
In article <1F37P47@xds13.ferranti.com>,
	peter@ficc.ferranti.com (Peter da Silva) writes:
)...
)OK, so how do you pipe that here document through:
)
)	while read foo bar baz
)	do
)	  case $baz in
)	    coconuts) echo $foo $bar THEM;;
)	    *) su root -c 'rm -f /etc';;
)	  esac
)	done

cat << EOF | while read x
foo
bar
baz
EOF
do
	echo x=$x
done
--
"Please DON'T BREAK THE CHAIN!  Terry Wood broke the chain and ended up
writing COBOL PROGRAMS.  Three days later, he found his Blue Star Tatoo
Letter, made 20 copies and mailed them out.  He found a good job writing
compilers."  --  tjw@unix.cis.pitt.edu (Terry J. Wood)
Re: How do you pipe after a here document
#1845
Author: Wm E. Davidsen Jr
Date: Wed, 28 Nov 1990 03:12
37 lines
1527 bytes
In article <1F37P47@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:

| OK, so how do you pipe that here document through:
| 
| 	while read foo bar baz
| 	do
| 	  case $baz in
| 	    coconuts) echo $foo $bar THEM;;
| 	    *) su root -c 'rm -f /etc';;
| 	  esac
| 	done
| 
| (nope, stranger, it's "this here document")

  You can put the grep before the loop (and you don't need the cat):

        grep cocoanuts <<XX |
        your test here
        XX
        while...

  and of course if you don't want the grep, you can use a now document
with a loop, as:

        while read foo; do
	  process $foo
	done <<XX
	your now documant
	contents here!
	XX

  Which I admit is not something I find useful every day.
-- 
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me
Re: How do you pipe after a here document
#1878
Author: Conor P. Cahill
Date: Sun, 02 Dec 1990 00:29
24 lines
1093 bytes
In article <1F37P47@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>OK, so how do you pipe that here document through:
>
>	while read foo bar baz
>	do
>	  ....
>	done

With the following:

#! /bin/sh
cat <<END |
I,ve got
a lovely
bunch of coconuts
END
while read foo bar baz
do
	echo $foo
done
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads