using awk 
Author Message
 using awk

I am a newbie   in awk

  I'd like to capture a section of a  file starting from a 'start' pattern
  and ending at 'end' pattern

  I think awk can easily do that, just not sure how ??

  be real Glad if  someone can shed some lights

  cheers

  BRian



Mon, 16 Feb 2004 14:03:47 GMT  
 using awk
brian  choy wrote at Thursday 30 August 2001 08:03 like only he can:

Quote:
> I am a newbie   in awk

>   I'd like to capture a section of a  file starting from a 'start'
>   pattern and ending at 'end' pattern

>   I think awk can easily do that, just not sure how ??

>   be real Glad if  someone can shed some lights

>   cheers

>   BRian

Using GNU awk, something like this should do the trick, numerous
solutions are possible.

awk '{if ($0~/End/){print;exit 1}}/Start/{s=1};s==1{print}' infile

Michael Heiming



Mon, 16 Feb 2004 14:43:07 GMT  
 using awk

Quote:
> I am a newbie   in awk

>   I'd like to capture a section of a  file starting from a 'start' pattern
>   and ending at 'end' pattern

>   I think awk can easily do that, just not sure how ??

>   be real Glad if  someone can shed some lights

One way is use the `start' pattern to set a flag to true ( not zero)
then set the flag to zero with the `end' pattern.

Then base the printing on the boolean `truth' of the flag.

It would look like this:

awk '/START/{ flag = 1 }
     /END/{ flag = 0 }
     flag {print $0}' infile

The last line is just a sort of short hand way of testing the variable
`flag' for its boolean truth.  What happens is that every line awk sees
while the flag is set to one will be printed.  When flag is set to
zero printing halts.

So,  printing starts when your `start' pattern appears and ends when your
`end' pattern appears.



Mon, 16 Feb 2004 14:36:57 GMT  
 using awk

Quote:
>   I'd like to capture a section of a  file starting from a 'start' pattern
>   and ending at 'end' pattern

>   I think awk can easily do that, just not sure how ??

For example...

/start/, /end/ {print}

...will print all records between the "start" and "end" patterns.

Regards,
   =Adrian=



Mon, 16 Feb 2004 16:02:01 GMT  
 using awk

Quote:
> I am a newbie   in awk

>   I'd like to capture a section of a  file starting from a 'start' pattern
>   and ending at 'end' pattern

/Start/,/End/ { print }

(Pg.188: S.R.Bourne, The UNIX System, Addison-Wesley 1983)

Jurgen



Mon, 16 Feb 2004 19:09:51 GMT  
 using awk


Quote:
> > I am a newbie   in awk

> >   I'd like to capture a section of a  file starting from a 'start'
pattern
> >   and ending at 'end' pattern

> /Start/,/End/ { print }

> (Pg.188: S.R.Bourne, The UNIX System, Addison-Wesley 1983)

I guess if you are a lazy typist then you might prefer sed:

sed -n '/Start/,/End/p' infile >outfile

HTH
--
Peter S Tillier

Opinions expressed are my own and not necessarily
those of my employer.



Mon, 16 Feb 2004 22:31:26 GMT  
 using awk


Quote:




>> > I am a newbie   in awk

>> >   I'd like to capture a section of a  file starting from a 'start'
>pattern
>> >   and ending at 'end' pattern

>> /Start/,/End/ { print }

>> (Pg.188: S.R.Bourne, The UNIX System, Addison-Wesley 1983)
>I guess if you are a lazy typist then you might prefer sed:

>sed -n '/Start/,/End/p' infile >outfile

a lazy typist would choose awk:

awk '/Start/,/End/' infile >outfile

without an action specified, {print $0} is assumed by awk

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 16 Feb 2004 23:44:38 GMT  
 using awk

Quote:

<snip>
> a lazy typist would choose awk:

> awk '/Start/,/End/' infile >outfile

> without an action specified, {print $0} is assumed by awk

Nice one, Chuck!  One of the times when awk's defaults are better than
sed's!

--
Peter S Tillier
"Who needs Perl when you can write dc 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, 17 Feb 2004 01:52:33 GMT  
 using awk

Quote:

>I am a newbie   in awk

>  I'd like to capture a section of a  file starting from a 'start' pattern
>  and ending at 'end' pattern

>  I think awk can easily do that, just not sure how ??

>  be real Glad if  someone can shed some lights

The simplest way is
awk '/start/,/end/'


Mon, 16 Feb 2004 16:09:01 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. using awk to change a $ in a document

2. need help using AWK

3. Copy files using AWK's output

4. using awk to edit a single line

5. Insert/update on files using awk

6. using awk in a shell script...

7. process only last record using awk

8. Substituting single quotes from Perl via shell using awk and gsub

9. Update lines using awk

10. using awk to format ifconfig -a output

11. a basic question on how to simulate grep -v using awk

12. How to handle comma in the fields winthin a csv file using awk

 

 
Powered by phpBB® Forum Software