For Programmers: Free Programming Magazines  


Home > Archive > AWK > August 2007 > seeking help on searching and appending









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author seeking help on searching and appending
sammy

2007-08-26, 7:59 am

Appreciate some awk help

Have a shortened version of a text file as shown below.

Would like to create an awk script to be able to produce an output as shown
at the end of this message.

I would like to search for a string such as ccc_1 and have this line
appended to the time value above
The number of lines down for ccc_1 from the time value such as (16:00) or
whatever hour time may vary.

Hope what I'm trying to achieve makes sense.

Sammy


FILE

fr24aug07
STRING OF TEXT
STRING OF TEXT
16:00
vvv_1
string of text for vv
bbb_1
string of text for b bb
ccc_1
string of text for cc
ddd_1
string of text for dd dd
15:00
vvv_1
string of text for vvvv
bbb_1
string of text for bbb
ccc_1
string of text for cc cc
ddd_1
string of text for dddddd
th23aug07
STRING OF TEXT
STRING OF TEXT
16:00
.... and so on


OUTPUT OF FILE ABOVE

fr24aug07
STRING OF TEXT
STRING OF TEXT
16:00 ccc_1 string of text for cc
15:00 ccc_1 string of text for cc cc
th23aug07
STRING OF TEXT
STRING OF TEXT
16:00 ccc_1 string of text for ccccc continuation of another day
15:00 ccc_1 string of text for c c c


Ed Morton

2007-08-26, 7:59 am

sammy wrote:
> Appreciate some awk help
>
> Have a shortened version of a text file as shown below.
>
> Would like to create an awk script to be able to produce an output as shown
> at the end of this message.
>
> I would like to search for a string such as ccc_1 and have this line
> appended to the time value above
> The number of lines down for ccc_1 from the time value such as (16:00) or
> whatever hour time may vary.
>
> Hope what I'm trying to achieve makes sense.
>
> Sammy
>
>
> FILE
>
> fr24aug07
> STRING OF TEXT
> STRING OF TEXT
> 16:00
> vvv_1
> string of text for vv
> bbb_1
> string of text for b bb
> ccc_1
> string of text for cc
> ddd_1
> string of text for dd dd
> 15:00
> vvv_1
> string of text for vvvv
> bbb_1
> string of text for bbb
> ccc_1
> string of text for cc cc
> ddd_1
> string of text for dddddd
> th23aug07
> STRING OF TEXT
> STRING OF TEXT
> 16:00
> ... and so on
>
>
> OUTPUT OF FILE ABOVE
>
> fr24aug07
> STRING OF TEXT
> STRING OF TEXT
> 16:00 ccc_1 string of text for cc
> 15:00 ccc_1 string of text for cc cc
> th23aug07
> STRING OF TEXT
> STRING OF TEXT
> 16:00 ccc_1 string of text for ccccc continuation of another day
> 15:00 ccc_1 string of text for c c c
>
>


How do you know to discard "ddd_1", etc. but keep "th23aug07"?

Ed.
sammy

2007-08-26, 6:58 pm

Well I would like to just search for the single string ccc_1 or a similar
pattern ???_1 using awks /ccc_1/ but also keep the dates
dates eg ( fr24aug07 ) and the STRING OF TEXT, 2 lines that immediately
follows the date.

"Ed Morton" <morton@lsupcaemnt.com> wrote in message
news:PdOdnWcJ5bXK_0zbnZ2dnUVZ_qrinZ2d@co
mcast.com...
> sammy wrote:
>
> How do you know to discard "ddd_1", etc. but keep "th23aug07"?
>
> Ed.



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com