print contents up to blank line 
Author Message
 print contents up to blank line

I've got about 3000 of the following files:

<file start>
TIME: lbsys 04-07-2002 19:50
 10  474   0 3552   130   11  735   19  148   21    0  2371    3   7  
0  90
 11 2305   0 1364   241   87  579   56  185   26    0  3852   18  32  
3  47
 14  762   0  976   123    0  455   24  162   27    0  1325    0  14  
0  86
 15 1021   0  744   202   82  580   20  152   30    0  2523    8  12  
3  77
 18  441   0 1415   123    6  740   17  133   19    0  2160   11   4  
0  85
 19 1371   0 1273   308   99  326   31  141   14    0  1990    9  18  
0  73

-------------------------------
<EOF>

I need to print everything between TIME and the first blank line.
Normally I would just use NR > 1 && NR < 7 to get just the performance
data. However, some of the files a different number of data rows:

<file start>
TIME: erin 04-07-2002 06:20
  0  111   0  129   257   55   87    1    4    4    0   128    0   2  
9  89
  1  102   0  113    89   87  120    5    5    2    0   210    0   2  
9  89

-------------------------------
<EOF>

With this in mind, I would like to print from NR > 1 to the first
blank line awk encounters. I tried the following, but it bombed out
immediately:

nawk 'NR > 1 && NR < /^$/ {(print statments here)}' $file

also tried it with different qouting parameters, etc. but no luck, any
ideas?



Mon, 27 Sep 2004 01:00:38 GMT  
 print contents up to blank line
Easiest:
/TIME/  { print=1; next }
/^$/    { exit )
print   { print $0 }
Quote:

> I've got about 3000 of the following files:

> <file start>
> TIME: lbsys 04-07-2002 19:50
>  10  474   0 3552   130   11  735   19  148   21    0  2371    3   7
> 0  90
>  11 2305   0 1364   241   87  579   56  185   26    0  3852   18  32
> 3  47
>  14  762   0  976   123    0  455   24  162   27    0  1325    0  14
> 0  86
>  15 1021   0  744   202   82  580   20  152   30    0  2523    8  12
> 3  77
>  18  441   0 1415   123    6  740   17  133   19    0  2160   11   4
> 0  85
>  19 1371   0 1273   308   99  326   31  141   14    0  1990    9  18
> 0  73

> -------------------------------
> <EOF>

> I need to print everything between TIME and the first blank line.
> Normally I would just use NR > 1 && NR < 7 to get just the performance
> data. However, some of the files a different number of data rows:

> <file start>
> TIME: erin 04-07-2002 06:20
>   0  111   0  129   257   55   87    1    4    4    0   128    0   2
> 9  89
>   1  102   0  113    89   87  120    5    5    2    0   210    0   2
> 9  89

> -------------------------------
> <EOF>

> With this in mind, I would like to print from NR > 1 to the first
> blank line awk encounters. I tried the following, but it bombed out
> immediately:

> nawk 'NR > 1 && NR < /^$/ {(print statments here)}' $file

> also tried it with different qouting parameters, etc. but no luck, any
> ideas?



Mon, 27 Sep 2004 01:09:44 GMT  
 print contents up to blank line

Quote:
>I've got about 3000 of the following files:

><file start>
>TIME: lbsys 04-07-2002 19:50
> 10  474   0 3552   130   11  735   19  148   21    0  2371    3   7  
>0  90
> 11 2305   0 1364   241   87  579   56  185   26    0  3852   18  32  
>3  47
> 14  762   0  976   123    0  455   24  162   27    0  1325    0  14  
>0  86
> 15 1021   0  744   202   82  580   20  152   30    0  2523    8  12  
>3  77
> 18  441   0 1415   123    6  740   17  133   19    0  2160   11   4  
>0  85
> 19 1371   0 1273   308   99  326   31  141   14    0  1990    9  18  
>0  73

>-------------------------------
><EOF>

>I need to print everything between TIME and the first blank line.
>Normally I would just use NR > 1 && NR < 7 to get just the performance
>data. However, some of the files a different number of data rows:

><file start>
>TIME: erin 04-07-2002 06:20
>  0  111   0  129   257   55   87    1    4    4    0   128    0   2  
>9  89
>  1  102   0  113    89   87  120    5    5    2    0   210    0   2  
>9  89

>-------------------------------
><EOF>

>With this in mind, I would like to print from NR > 1 to the first
>blank line awk encounters. I tried the following, but it bombed out
>immediately:

>nawk 'NR > 1 && NR < /^$/ {(print statments here)}' $file

>also tried it with different qouting parameters, etc. but no luck, any
>ideas?

awk '/^$/{exit}NR>1' "$file"

regards

--

                # if you are bored crack my sig.
1F8B0808CABB793C0000666667002D8E410E83300C04EF91F2877D00CA138A7A
EAA98F30C494480157B623C4EF1B508FDED1CEFA9152A23DE35D661593C5318E
630C313CD701BE92E390563326EE17A3CA818F5266E4C2461547F1F5267659CA
8EE2092F76C329ED02CA430C5373CC62FF94BAC6210B36D9F9BC4AB53378D978
80F2978A1A6E5D6F5133B67B6113178DC1059526698AFE5C17A5187E7D930492



Mon, 27 Sep 2004 01:21:54 GMT  
 print contents up to blank line

% I've got about 3000 of the following files:
%
% <file start>
% TIME: lbsys 04-07-2002 19:50
%  10  474   0 3552   130   11  735   19  148   21    0  2371    3   7  
% 0  90
%  11 2305   0 1364   241   87  579   56  185   26    0  3852   18  32  
% 3  47
%  14  762   0  976   123    0  455   24  162   27    0  1325    0  14  
% 0  86
%  15 1021   0  744   202   82  580   20  152   30    0  2523    8  12  
% 3  77
%  18  441   0 1415   123    6  740   17  133   19    0  2160   11   4  
% 0  85
%  19 1371   0 1273   308   99  326   31  141   14    0  1990    9  18  
% 0  73
%
%
% -------------------------------
% <EOF>
%
% I need to print everything between TIME and the first blank line.

You could use the range operator. I'm so e{*filter*}d -- it hardly ever
does what anyone wants.

 /TIME/,!NF

ought to do it
--

Patrick TJ McPhee
East York  Canada



Mon, 27 Sep 2004 12:16:09 GMT  
 print contents up to blank line


Quote:
> I've got about 3000 of the following files:

> <file start>
> TIME: lbsys 04-07-2002 19:50
>  10  474   0 3552   130   11  735   19  148   21    0  2371    3   7  
> 0  90
>  11 2305   0 1364   241   87  579   56  185   26    0  3852   18  32  
> 3  47
>  14  762   0  976   123    0  455   24  162   27    0  1325    0  14  
> 0  86
>  15 1021   0  744   202   82  580   20  152   30    0  2523    8  12  
> 3  77
>  18  441   0 1415   123    6  740   17  133   19    0  2160   11   4  
> 0  85
>  19 1371   0 1273   308   99  326   31  141   14    0  1990    9  18  
> 0  73

> -------------------------------
> <EOF>

> I need to print everything between TIME and the first blank line.
> Normally I would just use NR > 1 && NR < 7 to get just the performance
> data. However, some of the files a different number of data rows:

> <file start>
> TIME: erin 04-07-2002 06:20
>   0  111   0  129   257   55   87    1    4    4    0   128    0   2  
> 9  89
>   1  102   0  113    89   87  120    5    5    2    0   210    0   2  
> 9  89

> -------------------------------
> <EOF>

> With this in mind, I would like to print from NR > 1 to the first
> blank line awk encounters. I tried the following, but it bombed out
> immediately:

My grotesque "contribution" :

awk '{RS="";print}'|grep -v ^TIME

ouch no pipes allowed in this NG - sorry : >



Mon, 27 Sep 2004 23:00:47 GMT  
 print contents up to blank line
...

Quote:
>My grotesque "contribution" :

>awk '{RS="";print}'|grep -v ^TIME

Both too grotesque and not enough so! You should assign RS in a BEGIN block or
on the command line, else the first record is read using the default RS. Also,
it's *never* necessary to use grep with awk. I have nothing against pipes, but
I don't care for unnecessary processes.

Patrick already showed the range operator, which seems to print the TIME line
and the first blank line afterwards, which doesn't seem to be what the OP
wants.

Personally, I'd opt for the inelegant but robust

/^TIME/ { printme = 1; next }
/^[ \t]*$/ { exit }
printme



Tue, 28 Sep 2004 13:24:43 GMT  
 print contents up to blank line

Quote:

> ...
> >My grotesque "contribution" :

> >awk '{RS="";print}'|grep -v ^TIME

> Both too grotesque and not enough so! You should assign RS in a BEGIN
block or
> on the command line, else the first record is read using the default
RS. Also,
> it's *never* necessary to use grep with awk. I have nothing against
pipes, but
> I don't care for unnecessary processes.

> Patrick already showed the range operator, which seems to print the
TIME line
> and the first blank line afterwards, which doesn't seem to be what the
OP
> wants.

Yes, that's one of awk's range operator drawbacks insofaras it always
includes the start and end lines in the output.  The only simple way to
eliminate them is to use a flag to decide whether to print as you do in
the following example.

Quote:
> Personally, I'd opt for the inelegant but robust

> /^TIME/ { printme = 1; next }
> /^[ \t]*$/ { exit }
> printme

Although for the given data Laura's solution seems more elegant...

Peter
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"
peter{dot}tillier<at>btinternet[dot]com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Tue, 28 Sep 2004 14:54:50 GMT  
 print contents up to blank line


Quote:

> ...
>>My grotesque "contribution" :

>>awk '{RS="";print}'|grep -v ^TIME

> Both too grotesque and not enough so! You should assign RS in a BEGIN block or
> on the command line, else the first record is read using the default RS. Also,
> it's *never* necessary to use grep with awk. I have nothing against pipes, but
> I don't care for unnecessary processes.

excellent response : > Me neither. Wasnt aware of that RS BEGIN gotcha.
Please provide an example of where RS without a BEGIN will
hiccup in this context. I am assuming the example was line wrapped
weird and did not begin with a space character(!)

OPs truncated example:
<file start>
TIME: erin 04-07-2002 06:20
^^ no space
  0  111   0  129   257   55   87    1    4    4    0   128    0   2  
9  89
^^^ line 2 wrapped begins with white space

My horrible solution even works with Solaris old awk : <



Tue, 28 Sep 2004 23:25:45 GMT  
 print contents up to blank line
...

Quote:
>excellent response : > Me neither. Wasnt aware of that RS BEGIN
gotcha.
>Please provide an example of where RS without a BEGIN will
>hiccup in this context. I am assuming the example was line wrapped
>weird and did not begin with a space character(!)

The point was general. For the OP's sample data, no big deal. However,
if the first line were blank, your awk script and grep commands would
pass it along to ultimate stdout.

One point I didn't make was that the OP clearly wanted to end output
at the first blank line following the first /^TIME/ line, exclusive.
Your script would print any subsequent nonblank records. Useful, but
not what the OP asked for.



Wed, 29 Sep 2004 07:30:01 GMT  
 print contents up to blank line

Quote:



> > ...
> >>My grotesque "contribution" :

> >>awk '{RS="";print}'|grep -v ^TIME

> > Both too grotesque and not enough so! You should assign RS in a
BEGIN block or
> > on the command line, else the first record is read using the default
RS. Also,
> > it's *never* necessary to use grep with awk. I have nothing against
pipes, but
> > I don't care for unnecessary processes.

> excellent response : > Me neither. Wasnt aware of that RS BEGIN
gotcha.
> Please provide an example of where RS without a BEGIN will
> hiccup in this context. I am assuming the example was line wrapped
> weird and did not begin with a space character(!)

Harlan's point was that for a POSIX awk setting RS in the rule as you
have done is too late, because the first record will already have been
read and split using the default value of RS.  What {RS="";print} does
is to set the separator to any number of blank lines for subsequent
reads.  It may work apparently correctly for some old awks, but POSIX
compliant ones should not do so AFAIK.

Quote:
> OPs truncated example:
> <file start>
> TIME: erin 04-07-2002 06:20
> ^^ no space
>   0  111   0  129   257   55   87    1    4    4    0   128    0   2
> 9  89
> ^^^ line 2 wrapped begins with white space

> My horrible solution even works with Solaris old awk : <

As I said it may work with some, but it's not guaranteed hence the POSIX
version.

HTH
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"
peter{dot}tillier<at>btinternet[dot]com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Wed, 29 Sep 2004 16:10:02 GMT  
 print contents up to blank line
Hi,
        regarding the gerryt's one-liner:

awk '{RS="";print}'|grep -v ^TIME

Quote:

> >Please provide an example of where RS without a BEGIN will
> >hiccup in this context. [...]


Quote:
> The point was general. For the OP's sample data, no big deal. However,
> if the first line were blank, your awk script and grep commands would
> pass it along to ultimate stdout.

To me, all seems clear: first line is first record (old RS), then
everything up to first blank line is second record.
Are there any differences between old/new/posix implementations?

Quote:
> One point I didn't make was that the OP clearly wanted to end output
> at the first blank line following the first /^TIME/ line, exclusive.

Yes, that's clear.  Could be fixed:

        awk '{print; if(RS)RS="";else exit}}'|grep -v ^TIME

But you're right, grep is never necessary with awk:

        awk '{if(RS)RS="";else{print;exit}}'

or
        awk '!RS{print;exit};/^TIME/{RS=""}'

(The second solution even seems to be equivalent to your robust
inelegant solution.  It just misses its readability ;-)

Have a nice day,
        Stepan



Sat, 09 Oct 2004 15:18:14 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Student needs help with printing blank line....

2. Student needs help with printing blank line....

3. remove blank lines before lines beginning with string

4. blank lines/lines with spaces (how to remove)

5. Print panel prints blank pages

6. inserting a blank line in a file

7. to insert a blank line

8. adding blank lines to text file

9. datafile has blank lines

10. Blank lines

11. Removing data between blank lines

12. line beginning with a blank

 

 
Powered by phpBB® Forum Software