From owner-freebsd-questions@FreeBSD.ORG Thu Sep 14 12:08:09 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DF86C16A407 for ; Thu, 14 Sep 2006 12:08:09 +0000 (UTC) (envelope-from ohartman@uni-mainz.de) Received: from mailgate02.zdv.uni-mainz.de (mailgate02.zdv.Uni-Mainz.DE [134.93.178.132]) by mx1.FreeBSD.org (Postfix) with ESMTP id 916C643D55 for ; Thu, 14 Sep 2006 12:08:07 +0000 (GMT) (envelope-from ohartman@uni-mainz.de) Received: from exfront01.zdv.uni-mainz.de ([134.93.176.49]) by mailgate02.zdv.uni-mainz.de with ESMTP; 14 Sep 2006 14:08:06 +0200 Received: from mail.uni-mainz.de ([134.93.176.56]) by exfront01.zdv.Uni-Mainz.DE with Microsoft SMTPSVC(6.0.3790.1830); Thu, 14 Sep 2006 14:08:06 +0200 Received: from [130.133.86.198] ([130.133.86.198] RDNS failed) by mail.uni-mainz.de over TLS secured channel with Microsoft SMTPSVC(6.0.3790.1830); Thu, 14 Sep 2006 14:08:06 +0200 Message-ID: <45094622.7010803@uni-mainz.de> Date: Thu, 14 Sep 2006 14:08:02 +0200 From: "O. Hartmann" User-Agent: Thunderbird 1.5.0.5 (X11/20060731) MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 14 Sep 2006 12:08:06.0396 (UTC) FILETIME=[6FC843C0:01C6D7F6] Subject: OT: awk/sed: how to use a variable in an address range? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2006 12:08:10 -0000 Hello. This might be OT in FreeBSD list, but hopefully some of yours is involved in sophisticated AWK programming. To keep a small shell script portable I use awk for separating an ASCII file from a home brewn scientific model software. The datasets of the output is enclosed by /begin_data_set_##/ . . . /end_data_set_##/ ## is a two-digit counter, but not necessesaryly equidistant. I would like to separate the file contaning all datasets via awk or sed into appropriate files - this is my intention, but I failed. the simplest way - in theory and in my limitit ability of using sed or awk - is to print all lines between the (sed/awk) addresses /begin_data_set_##/ ... /end_data_set_##/ but this does not work due to i cannot use variables in the address range specifiers neither in awk nor in sed like this: awk -v nc=$NUMBER '/\/begin_data_set_nc\//,/\/end_data_set_nc\// { do-something-in-awk}' $input_file > $output_file_$NUMBER nc in this example is set to the counter of the desired dataset. I would like to use SED or AWK only due to portability reasons. Any hints are appreciated. Regards, oh