csh use of grep | tr commands
@lbutlr
kremels at kreme.com
Tue Aug 11 14:52:12 UTC 2020
On 10 Aug 2020, at 08:44, Polytropon <freebsd at edvax.de> wrote:
> On Sun, 09 Aug 2020 20:34:51 -0400, Ernie Luzar wrote:
>> Double quotes are giving me trouble.
>>
>> I have a file with a line in it like this
>> ip4="10.111.098.2"
>> I want to get just the ip address
>>
>> ip=`grep "ip4=" directory-path/file-name
>>
>> $ip ends up having ip4="10.111.098.2" in it
>>
>> ip=`echo -n "${ip}" | tr -d "ip4="
>>
>> $ip ends up having "10.111.098.2" in it
>>
>> Putting | tr """ " "` after the echo above gives error.
>>
>> How do I remove the " around the ip address?
>
> Without any insult: You're using the wrong tool.
>
> While the C shell is acceptable as an interactive shell
> (and I even prefer it over bash to a certain degree),
> it's absolutely terrible, and I may even say unsuited
> for scripting.
I agree. My first use of a unix system defaulted to csh. As soon as I started writing scripts I switched away from csh. (bash and now zsh).
> The system's default scripting shell is sh. Use that.
Or that.
> % echo 'those "are" quotes' | sed 's/"//g'
Exactly what I would do, though I sometimes I use egrep -o if there is longer input.
--
I WILL NOT SELL LAND IN FLORIDA Bart chalkboard Ep. 7F16
More information about the freebsd-questions
mailing list