OT: awk/sed: how to use a variable in an address range?
O. Hartmann
ohartman at uni-mainz.de
Thu Sep 14 05:08:10 PDT 2006
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
More information about the freebsd-questions
mailing list