Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

docmd.close 2585, WWWXXXAPC, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text, how to setup procmail html2text, WWWXXXAPC., XXXCNZZZ

Links

XODOX
Impressum

#1: cat and grep redirection

Posted on 2006-12-10 08:18:51 by cconnell

Hi,
I am trying to do something in my script as follows, it sends the
following output to the file hosts as follows:

mgt=b01
cat >> ./hosts <<EOF
#
#
10.32.25.34 b01
10.32.25.35 b02
10.32.25.36 b03
EOF

I want to cat the output to the hosts file but 'exclude' the line if
the line has the value of the 'mgt' variable so in the above example I
would get in the hosts file.

#
#
10.32.25.35 b02
10.32.25.36 b03


I have tried using cat with grep -v "$mgt" with no luck. I think Im
redirecting something wrong. Thanks for any help.

Report this message

#2: Re: cat and grep redirection

Posted on 2006-12-10 08:34:01 by Klaus Alexander Seistrup

cconnell_1@lycos.com wrote:

> mgt=b01
> cat >> ./hosts <<EOF
> #
> #
> 10.32.25.34 b01
> 10.32.25.35 b02
> 10.32.25.36 b03
> EOF
>
> [...]
>
> I have tried using cat with grep -v "$mgt" with no luck.

This works for me:

#v+

mgt=b01
grep -v "$mgt" <<EOF >>./hosts
#
#
10.32.25.34 b01
10.32.25.35 b02
10.32.25.36 b03
EOF

#v-

Cheers,

--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

Report this message

#3: Re: cat and grep redirection

Posted on 2006-12-10 08:42:33 by RolandRB

cconnell_1@lycos.com wrote:
> Hi,
> I am trying to do something in my script as follows, it sends the
> following output to the file hosts as follows:
>
> mgt=b01
> cat >> ./hosts <<EOF
> #
> #
> 10.32.25.34 b01
> 10.32.25.35 b02
> 10.32.25.36 b03
> EOF
>
> I want to cat the output to the hosts file but 'exclude' the line if
> the line has the value of the 'mgt' variable so in the above example I
> would get in the hosts file.
>
> #
> #
> 10.32.25.35 b02
> 10.32.25.36 b03
>
>
> I have tried using cat with grep -v "$mgt" with no luck. I think Im
> redirecting something wrong. Thanks for any help.

It works for me:

mgt=b01
cat << EOF | grep -v "$mgt" > roland.txt
#
#
10.32.25.34 b01
10.32.25.35 b02
10.32.25.36 b03
EOF

cat roland.txt

Report this message