From owner-freebsd-questions@FreeBSD.ORG Tue Dec 18 20:42:28 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 51C1A9B for ; Tue, 18 Dec 2012 20:42:28 +0000 (UTC) (envelope-from rwmaillists@googlemail.com) Received: from mail-ea0-f182.google.com (mail-ea0-f182.google.com [209.85.215.182]) by mx1.freebsd.org (Postfix) with ESMTP id C97818FC14 for ; Tue, 18 Dec 2012 20:42:27 +0000 (UTC) Received: by mail-ea0-f182.google.com with SMTP id a14so485758eaa.41 for ; Tue, 18 Dec 2012 12:42:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:content-transfer-encoding; bh=aeHy/CI3SLR00PaP3FrhYbE6kT0DXqrsrKosJgVrlpo=; b=r9r8Mrhak8Nmqh+SXhY86J+iVYpJK1g1WRvuhGiZDUH/9lX00moR84uiKALWdQ4j59 bZL/uUjHoPszXJJmEjYMCGk/uhabNmpCnOghhzFsOM/DhT6qfNfmD6Gl2zc9L6c+JcGa Ohtr0nm58MFelm6diJYp7Y/BEiOL867LKcxPDsRHjonNAHol+0sk1+ILb6nR/2HMhXw+ k9dOEeB2/ysabZT8Z90J7BgdOMAlwUzKuW7KTtBGO6NhE5fUJaBSRtTXRaRO/hjxfApJ C+x6/4GWc1l+arYqNwGOkyX/m9MrHssJwK+eImjWsszkhbEN7JUa4KE1borm7BXmJlnQ 30BA== X-Received: by 10.14.203.2 with SMTP id e2mr8516871eeo.20.1355861858572; Tue, 18 Dec 2012 12:17:38 -0800 (PST) Received: from gumby.homeunix.com (87-194-105-247.bethere.co.uk. [87.194.105.247]) by mx.google.com with ESMTPS id k4sm5204111eep.15.2012.12.18.12.17.35 (version=SSLv3 cipher=OTHER); Tue, 18 Dec 2012 12:17:37 -0800 (PST) Date: Tue, 18 Dec 2012 20:17:33 +0000 From: RW To: freebsd-questions@freebsd.org Subject: Re: using AWK Message-ID: <20121218201733.06f78f1f@gumby.homeunix.com> In-Reply-To: <18B0C79B-AF04-48D1-AF26-1B8A8B3641C1@fisglobal.com> References: <1355744359.61103.YahooMailNeo@web160104.mail.bf1.yahoo.com> <18B0C79B-AF04-48D1-AF26-1B8A8B3641C1@fisglobal.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.6; amd64-portbld-freebsd8.3) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2012 20:42:28 -0000 On Mon, 17 Dec 2012 08:16:26 -0800 Devin Teske wrote: > > On Dec 17, 2012, at 3:39 AM, Jack Mc Lauren wrote: > > > Hi guys > > > > How can I read a file which contains a number and assign that > > number to a variable via awk programming? By the way, I want to use > > this awk program in a shell script. > > > > Thanks in advance > > Try this: > > awk -v file=/etc/ttys 'BEGIN { getline line from %s: %s\n", file, line }' > Semms a bit complicated when you could set the awk variable directly e.g. $ echo 42 > /tmp/f $ awk -v x=`cat /tmp/f` 'BEGIN{ print x+1 }' 43