Hi,
I need to print the contents of a file from the beginning until the
given pattern is found, then stop.
Using patterns I need to give both begpat and endpat - is there anyway
to do this giving just the endpat as I would not know what the file
start will be.
Thanks
|
|
0
|
|
|
|
Reply
|
sharmil2006 (1)
|
11/13/2007 1:19:19 PM |
|
On 13 , 15:19, shrgh <sharmil2...@gmail.com> wrote:
> Hi,
>
> I need to print the contents of a file from the beginning until the
> given pattern is found, then stop.
>
> Using patterns I need to give both begpat and endpat - is there anyway
> to do this giving just the endpat as I would not know what the file
> start will be.
>
> Thanks
/pattern/ { exit }
{ print }
Vassilis
|
|
0
|
|
|
|
Reply
|
Vassilis
|
11/13/2007 1:23:03 PM
|
|
On Nov 13, 6:23 pm, Vassilis <b.alexand...@gmail.com> wrote:
> On 13 , 15:19, shrgh <sharmil2...@gmail.com> wrote:
>
> > Hi,
>
> > I need to print the contents of a file from the beginning until the
> > given pattern is found, then stop.
>
> > Using patterns I need to give both begpat and endpat - is there anyway
> > to do this giving just the endpat as I would not know what the file
> > start will be.
>
> > Thanks
>
> /pattern/ { exit }
> { print }
>
> Vassilis
Great! it worked :-) thanks. The pattern is not included,though-any
way to print the pattern and then stop
|
|
0
|
|
|
|
Reply
|
shrgh
|
11/13/2007 1:35:44 PM
|
|
On 11/13/2007 7:35 AM, shrgh wrote:
> On Nov 13, 6:23 pm, Vassilis <b.alexand...@gmail.com> wrote:
>
>>On 13 , 15:19, shrgh <sharmil2...@gmail.com> wrote:
>>
>>
>>>Hi,
>>
>>>I need to print the contents of a file from the beginning until the
>>>given pattern is found, then stop.
>>
>>>Using patterns I need to give both begpat and endpat - is there anyway
>>>to do this giving just the endpat as I would not know what the file
>>>start will be.
>>
>>>Thanks
>>
>>/pattern/ { exit }
>>{ print }
>>
>> Vassilis
>
>
> Great! it worked :-) thanks. The pattern is not included,though-any
> way to print the pattern and then stop
>
C'mon, don't tell me you couldn't have figured this one out with a tiny bit of
thoughr:
{ print }
/pattern/ { exit }
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
11/13/2007 2:14:45 PM
|
|
In article <1194959959.390983.115000@d55g2000hsg.googlegroups.com>,
shrgh <sharmil2006@gmail.com> wrote:
>Hi,
>
>I need to print the contents of a file from the beginning until the
>given pattern is found, then stop.
>
>Using patterns I need to give both begpat and endpat - is there anyway
>to do this giving just the endpat as I would not know what the file
>start will be.
I think the answer you are looking for is:
NR==1,/endpat/
Interestingly, in my testing, the following did not work, but it seems
like it should. Anyone have any ideas why?
1,/endpat/
P.S. Yes, the first thing that came to my mind was the sort of solution
others have posted, where you exit when you hit the endpat, but a closer
reading of OP's text makes it clear that this is what they are looking
for.
|
|
0
|
|
|
|
Reply
|
gazelle
|
11/13/2007 2:27:03 PM
|
|
On 13 Nov., 15:27, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
> In article <1194959959.390983.115...@d55g2000hsg.googlegroups.com>,
>
> shrgh <sharmil2...@gmail.com> wrote:
> >Hi,
>
> >I need to print the contents of a file from the beginning until the
> >given pattern is found, then stop.
>
> >Using patterns I need to give both begpat and endpat - is there anyway
> >to do this giving just the endpat as I would not know what the file
> >start will be.
>
> I think the answer you are looking for is:
>
> NR==1,/endpat/
>
> Interestingly, in my testing, the following did not work, but it seems
> like it should. Anyone have any ideas why?
Yes. Because the block pattern matching is reset after each block.
Compare it to the code...
/BEGIN/,/END/
which will print _every_ BEGIN-END section in a file.
> 1,/endpat/
So after /endpat/ has been matched the next block starts where
condition 1 is true, which is always the case, starting from the
subsequent line of /endpat/.
Janis
> P.S. Yes, the first thing that came to my mind was the sort of solution
> others have posted, where you exit when you hit the endpat, but a closer
> reading of OP's text makes it clear that this is what they are looking
> for.
|
|
0
|
|
|
|
Reply
|
Janis
|
11/13/2007 2:50:04 PM
|
|
In article <1194965404.519982.256910@v2g2000hsf.googlegroups.com>,
Janis <janis_papanagnou@hotmail.com> wrote:
....
>Yes. Because the block pattern matching is reset after each block.
>
>Compare it to the code...
>
> /BEGIN/,/END/
>
>which will print _every_ BEGIN-END section in a file.
>
>
>> 1,/endpat/
>
>So after /endpat/ has been matched the next block starts where
>condition 1 is true, which is always the case, starting from the
>subsequent line of /endpat/.
Yes, of course. Makes perfect sense.
|
|
0
|
|
|
|
Reply
|
gazelle
|
11/13/2007 3:29:47 PM
|
|
|
6 Replies
236 Views
(page loaded in 0.078 seconds)
Similiar Articles: Large file problems - block pattern - comp.lang.awk... infile > This command works w/o file size issues. But how to print only 1st > and last matched pattern blocks ? ... Random access to content of archived files without ... Inset one file inside another file after matching line - comp.lang ...The condition is that AWK should search for the matching pattern first and insert the contents of the file ... If you don't need that, just do the "print" to stdout and ... print lines between two patterns - comp.lang.awk... pattern - Linux man page grep, egrep, fgrep - print lines matching a pattern Synopsis. grep [OPTIONS] PATTERN [FILE...] ... Print NUM lines of leading context before ... perl + regex bug? - comp.lang.perl.misc) Anyway, try printing the content of "$index" in hex before ... that anchored pattern matching. Here is what Klaus recommended I try: > > print "before ... this input file ... design pattern for a file converter... - comp.lang.java.programmer ...... be involved in just matching ... to shoehorn in a pattern before ... and build numerous patterns for sand castings and I ... Printing schematics spread across pages in pdf file ... print columns from bash variable - comp.lang.awkI printed n before and saw that its ... Join two lines in pattern matching, search, then assign fields to ... print columns from ... awk '{ print $1 '} file will print the first ... split at a pattern - comp.lang.awkI have a big file that that I need to split after a certain pattern is found into ... probably better to close each file before ... do > > awk -v n=1 '/EOD/{n++}{print>"file ... How can I print logged on "user name" on printed records - comp ...... so long as your not opening a file on ... gawk problem matching multiple patterns ?!? HOW-TO? - comp ... page is $0.10, and each user can print ... The job is printed out before ... Parsing file names with spaces - comp.lang.perl.misc... files = <DATA>; foreach (@files) { print; } contents of 'data' FILE ... back and not respond to most posts here until ... How about matching /:\d{2}\s+.*\s+.+\b ... How to write to file within awk ? - comp.lang.awk... 20s %5s\n", ele , x[ele] > "a1.txt" > } > print "Summary ... a2.txt" You only need >> in case you want to add to the file contents that a1.txt and a2.txt had *before ... Printing file contents until a pattern is matchedPrinting file contents until a pattern is matched - awk . This is a discussion on Printing file contents until a pattern is matched - awk; Hi, I need to print the ... grep, print lines matching a pattern - delorie softwarePrint the byte offset within the input file before each line of output. ... recursively, only files matching file_pattern will ... from the original file contents (to make ... 7/9/2012 5:40:12 PM
|