From owner-freebsd-questions@freebsd.org Mon Aug 10 14:44:57 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 50F3A3A5491 for ; Mon, 10 Aug 2020 14:44:57 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BQJf02cvQz4N1r for ; Mon, 10 Aug 2020 14:44:55 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([178.5.236.89]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPA (Nemesis) id 1Mdevh-1keCkG1omX-00ZfVi; Mon, 10 Aug 2020 16:44:53 +0200 Date: Mon, 10 Aug 2020 16:44:53 +0200 From: Polytropon To: Ernie Luzar Cc: "freebsd-questions@freebsd.org" Subject: Re: csh use of grep | tr commands Message-Id: <20200810164453.378835aa.freebsd@edvax.de> In-Reply-To: <5F30962B.5060005@gmail.com> References: <5F30962B.5060005@gmail.com> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:LZ7FOGa576k3CnStkwv6t02XqCZ7O1mqH/qlvf+zrAyt1CFjxrX Y2/STEHQvonSCe0FC3e+9Y/WKeDl2Xs8ALQO0aXzumvIy504AxO6I383hxbkWzw2f0I5aNB liu5044nHPNbexieuFJjF17pp0Wq0KyBs+649DmMG7Qfh8VIe/p5qZ5eHI9N1zLWnNWfiMd BVC7/hnmIlcw6q7KuI3tA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:/j/AXoXtzZg=:gPvB9q2zor3alH/F8FJJI7 nFbLeSObKOeRQ7UyEWHds9i0iGli02xvFjvhow4yzD+B2uKFZ6W29CTLEnIGDeozNRR1xtfbt pYgNlrxsPuVnD5Oa0leJTAqiGoUdD9ZoGe/quqNC+QZFQopNfYFVA2SthGb4RloS1P93VIXsX BvUjuNeTlAatr8hOfzRt6L26McluMoNjgI2hYpANPADoiweKYyyWdvrmjtCBPHH0FYBj2OY81 LvA9KNBgScDD4HzItz070mLgRALEH/ChHbJfPSGc7ms3eDoxe4BW9alKyyYOdQBMOzJFGAJZm B/Bphm5fgLy120HvnHKFxw/6qikMWSfo6accjS7Qu/4LPXbbMfH5MYSio5V+oPvW8qXy+t3Qa J8PcJUyUOfAz+2pLcPXS+BR0VjsaJ9H/2qaBkHijcvaOWpn9io1/aAE7MoiQR9NIiCGKp3Hfp FsPlR78aGrHgAj0jnjjlAeEmjYBDB16MJ+1VguJFuEayu1ScDEpiJ22HujhZxPIh6520n/w3n 1+Tu+NDeGmKPZMEMuLft+LUpuBn86kTCSOhlWBvuvHtepgS3bSosWCMaBbNJFDoTSQwCzT19i y/b52vdSeCpYjI/18f/Q7mO76vm7/rQ2mw6GGXt52xjReMzoCJDgc1E/ynB6wH27BTWYA68hp jAAtDSWFRlaDUmR+3W4S7kVaVMNZknXcAOBCBTTMDtDh++QWUHKPh485gtqlt8yP/U5mr6jy0 vyCT+rb1BxP8DrkZv9I26eO3kmNaIqRylQ/Xcw+hNB4p7biZeSufgLV7OOfYOW/Qc/RPJCaUT smVXSxsi80zHSWA6dZGlrigywcEaMwcRHvw4B2Xs9GgtGyT/ZiDWxyzX/MC3DHRsUf1P1Th X-Rspamd-Queue-Id: 4BQJf02cvQz4N1r X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of freebsd@edvax.de has no SPF policy when checking 212.227.126.187) smtp.mailfrom=freebsd@edvax.de X-Spamd-Result: default: False [2.46 / 15.00]; HAS_REPLYTO(0.00)[freebsd@edvax.de]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; HAS_ORG_HEADER(0.00)[]; NEURAL_HAM_SHORT(-0.23)[-0.228]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_TO(0.00)[gmail.com]; RECEIVED_SPAMHAUS_PBL(0.00)[178.5.236.89:received]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:8560, ipnet:212.227.0.0/16, country:DE]; ARC_NA(0.00)[]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-0.00)[-0.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[edvax.de]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(0.29)[0.293]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[212.227.126.187:from]; R_SPF_NA(0.00)[no SPF record]; RWL_MAILSPIKE_POSSIBLE(0.00)[212.227.126.187:from]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Aug 2020 14:44:57 -0000 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. The system's default scripting shell is sh. Use that. See "man sh" for quoting rules. It makes your life easier and more portable. :-) You can use bash to interactively develop sh scripts; even for creating one-liners bash is very convenient. Back on topic. If you don't mind an additional program call to sed, you can use the "replace with nothing" method: % echo 'those "are" quotes' | sed 's/"//g' those are quotes This example is from a C shell session. :-) Applied to your initial problem: % echo 'ip4="10.111.098.2"' | sed 's/ip4="//g; s/"//g' 10.111.098.2 You can use sed for multiple "replace with nothing" statements. Allow me to leave a pointer to the following article: Tom Christiansen: Csh Programming Considered Harmful http://harmful.cat-v.org/software/csh If you want to process some input files and do something with the lines they contain, use the right tool: This is often perl, but can also be sh or bash. It cannot be csh. That's the truth. ;-) I'd like to remind all readers that I've written one (in numbers: 1) script in the C shell which still works and which I still use from time to time. But I cannot recommend following my example, and I have promised to never do it again. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...