cat and grep redirection
am 10.12.2006 08:18:51 von 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 <
#
#
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.
Re: cat and grep redirection
am 10.12.2006 08:34:01 von Klaus Alexander Seistrup
cconnell_1@lycos.com wrote:
> mgt=b01
> cat >> ./hosts <
> #
> #
> 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" <>./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/
Re: cat and grep redirection
am 10.12.2006 08:42:33 von 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 <
> #
> #
> 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