Date: Thu, 14 Sep 2006 14:08:02 +0200 From: "O. Hartmann" <ohartman@uni-mainz.de> To: freebsd-questions@freebsd.org Subject: OT: awk/sed: how to use a variable in an address range? Message-ID: <45094622.7010803@uni-mainz.de>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45094622.7010803>
