From: mrkramer on
It is possible to change NR or FNR variable?

After getline fuction (in while loop) I would like to return to previous
line.


example file:
-----
1.ok
2.ok
3.ok
4.ok
5.error
6.foo
7.bar
8.ok
9.ok
10.error foo bar
11.ok
12.ok
13.ok
14.ok
15.eroor
16.foo
17.bar
18.ok
19.ok
----------

expected result
-------
5.error
6.foo
7.bar
10.error foo bar
15.error
16.foo
17.bar
--------


From: pk on
mrkramer wrote:

> It is possible to change NR or FNR variable?
>
> After getline fuction (in while loop) I would like to return to previous
> line.
>
>
> example file:
> -----
> 1.ok
> 2.ok
> 3.ok
> 4.ok
> 5.error
> 6.foo
> 7.bar
> 8.ok
> 9.ok
> 10.error foo bar
> 11.ok
> 12.ok
> 13.ok
> 14.ok
> 15.eroor
> 16.foo
> 17.bar
> 18.ok
> 19.ok
> ----------
>
> expected result
> -------
> 5.error
> 6.foo
> 7.bar
> 10.error foo bar
> 15.error
> 16.foo
> 17.bar
> --------

I can't see what getline has to do with your question, however see if this
works for you:

awk '!/^[0-9]+\.ok$/' file.txt
From: mrkramer on
pk napisal w dniu 2010-05-18 00:51:
> mrkramer wrote:
>
>> It is possible to change NR or FNR variable?
>>
>> After getline fuction (in while loop) I would like to return to previous
>> line.
>>
>>
>> example file:
>> -----
>> 1.ok
>> 2.ok
>> 3.ok
>> 4.ok
>> 5.error
>> 6.foo
>> 7.bar
>> 8.ok
>> 9.ok
>> 10.error foo bar
>> 11.ok
>> 12.ok
>> 13.ok
>> 14.ok
>> 15.eroor
>> 16.foo
>> 17.bar
>> 18.ok
>> 19.ok
>> ----------
>>
>> expected result
>> -------
>> 5.error
>> 6.foo
>> 7.bar
>> 10.error foo bar
>> 15.error
>> 16.foo
>> 17.bar
>> --------
>
> I can't see what getline has to do with your question, however see if this
> works for you:
>
> awk '!/^[0-9]+\.ok$/' file.txt
Thanks for reply. It works in this case, but I wrong described how
exactly looks my logfile.

My logfile has on begining of line time in format hhmmss.
Following there is some entries and somewhare in line is ERROR.
Next lines after ERROR has description that error but don't have hour on
begining.
No everyone error has description on next line.
Next line after this sequence there might be entry with error or not. Of
course every entry begins by time in hhmmss format.

example file:
--------
112200.aaa.error
foo
bar
112201.aa.error
112202.bb.error
112203.ok
112204.ok
112205.ok
113201.aa.error
aaa
bbb
sql-err
113504.error
113650.ok
114056.ok
-------------

expected result:
--------------
112200.aaa.error
foo
bar
112201.aa.error
112202.bb.error
1132.aa.error
aaa
bbb
aql-err
113504.error
----------------

Now I solved this using awk and functions built in this program, but I'm
curious any other ideas how to achieve expected result.

From: Hermann Peifer on
On 18/05/2010 17:51, mrkramer wrote:
> pk napisal w dniu 2010-05-18 00:51:
> Thanks for reply. It works in this case, but I wrong described how
> exactly looks my logfile.
>
> My logfile has on begining of line time in format hhmmss.
> Following there is some entries and somewhare in line is ERROR.
> Next lines after ERROR has description that error but don't have hour on
> begining.
> No everyone error has description on next line.
> Next line after this sequence there might be entry with error or not. Of
> course every entry begins by time in hhmmss format.
>
> example file:
> --------
> 112200.aaa.error
> foo
> bar
> 112201.aa.error
> 112202.bb.error
> 112203.ok
> 112204.ok
> 112205.ok
> 113201.aa.error
> aaa
> bbb
> sql-err
> 113504.error
> 113650.ok
> 114056.ok
> -------------
>
> expected result:
> --------------
> 112200.aaa.error
> foo
> bar
> 112201.aa.error
> 112202.bb.error
> 1132.aa.error
> aaa
> bbb
> aql-err
> 113504.error
> ----------------
>
> Now I solved this using awk and functions built in this program, but I'm
> curious any other ideas how to achieve expected result.
>

awk '/error$/{desc=1;print;next}/ok$/{desc=0}desc'

(This will however not change 'sql-err' to 'aql-err')

Hermann
From: mrk on
Hermann Peifer napisal w dniu 2010-05-18 20:50:
> On 18/05/2010 17:51, mrkramer wrote:
>> pk napisal w dniu 2010-05-18 00:51:
>> Thanks for reply. It works in this case, but I wrong described how
>> exactly looks my logfile.
>>
>> My logfile has on begining of line time in format hhmmss.
>> Following there is some entries and somewhare in line is ERROR.
>> Next lines after ERROR has description that error but don't have hour on
>> begining.
>> No everyone error has description on next line.
>> Next line after this sequence there might be entry with error or not. Of
>> course every entry begins by time in hhmmss format.
>>
>> example file:
>> --------
>> 112200.aaa.error
>> foo
>> bar
>> 112201.aa.error
>> 112202.bb.error
>> 112203.ok
>> 112204.ok
>> 112205.ok
>> 113201.aa.error
>> aaa
>> bbb
>> sql-err
>> 113504.error
>> 113650.ok
>> 114056.ok
>> -------------
>>
>> expected result:
>> --------------
>> 112200.aaa.error
>> foo
>> bar
>> 112201.aa.error
>> 112202.bb.error
>> 1132.aa.error
>> aaa
>> bbb
>> aql-err
>> 113504.error
>> ----------------
>>
>> Now I solved this using awk and functions built in this program, but I'm
>> curious any other ideas how to achieve expected result.
>>
>
> awk '/error$/{desc=1;print;next}/ok$/{desc=0}desc'
>
> (This will however not change 'sql-err' to 'aql-err')
>
> Hermann
change sql-err to aql-err was just accident while write message ;-)
Expected result was written by me. It wasn't result any script.